0

Hi...

I've this:

random_name = ['Mohamed', 'Ahmed','Aboubakr']
print "1: %s    2: %s    3: %s" % (random_name[1], random_name[0], random_name[2])

I want to print all the three names but in random way,

as: some time: Mohamed, Ahmed, Aboubaker

and some time: Mohamed, Aboubaker, Ahmed

and some time: Aboubaker, Ahmed, Mohamed

and some time ...

I used random and it doesn't work correctely !!

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by pyTony
0

You are looking wrong place. Check itertools.permutations and random.choise

Edited by pyTony: n/a

1

You are looking for random.shuffle().
To see all method under random module use dir(random)
For help use help(random.shuffle)

>>> random_name = ['Mohamed', 'Ahmed','Aboubakr']
>>> random.shuffle(random_name)
>>> random_name
['Mohamed', 'Aboubakr', 'Ahmed']
>>> random.shuffle(random_name)
>>> random_name
['Ahmed', 'Mohamed', 'Aboubakr']
>>> random.shuffle(random_name)
>>> random_name
['Ahmed', 'Aboubakr', 'Mohamed']
>>>

Edited by snippsat: n/a

Votes + Comments
thanks
0

If you got your reply, it is your duty as OP (original poster) to close the thread as solved and give any reputation for excellent answer(s).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.