Alex Rivera | Logout

Why does itertools.permutations() return a list, instead of a string?

Asked 2011-11-13T18:27:33.870
35

Why does itertools.permutations() return a list of characters or digits for each permutation, instead of just returning a string?

For example:

>>> print([x for x in itertools.permutations('1234')])
>>> [('1', '2', '3', '4'), ('1', '2', '4', '3'), ('1', '3', '2', '4') ... ]

Why doesn't it return this?

>>> ['1234', '1243', '1324' ... ]
Edit
Report

1 Answer

16

Because it expects an iterable as a parameter and doesn't know, it's a string. The parameter is described in the docs.

http://docs.python.org/library/itertools.html#itertools.permutations

answered 2011-11-13T18:30:29.043

Your Answer