Python simple Code

Ian Kelly ian.g.kelly at gmail.com
Wed Jan 28 00:50:14 CET 2015


On Tue, Jan 27, 2015 at 4:22 PM, Salem Alqahtani <salem055 at gmail.com> wrote:
> I appreciate your answers and the output that I am expected from my simple code is the following:
>
> ['salem','Ali','sultan']
> ['salem','sultan','Ali']
> ['Ali','sultan','salem']
> ['Ali','salem','sultan']
> ['sultan','Ali','salem']
> ['sultan','salem','sultan']
>
> the 3 * 2 * 1 is 6 but I do not looking for this output.

>>> from itertools import permutations
>>> a = ['salem', 'Ali', 'sultan']
>>> for p in permutations(a):
...   print(list(p))
...
['salem', 'Ali', 'sultan']
['salem', 'sultan', 'Ali']
['Ali', 'salem', 'sultan']
['Ali', 'sultan', 'salem']
['sultan', 'salem', 'Ali']
['sultan', 'Ali', 'salem']



More information about the Python-list mailing list