How to convert result (in python) itertools.permutations ("0123456789") to a list of strings

In Python, I use list(itertools.permutations("0123456789")), and I get (I, as expected) a list of tuples of selected character strings.

Is there a way to turn this result into a list of strings without repeating all 3628800 items?

+5
source share
2 answers

If you want to do this without iterating over the entire list, and lazily executing it as needed, you can use itertools.imap:

itertools.imap(lambda x: "".join(x), itertools.permutations("0123456789"))

(note that I am not using the list()result permutationshere to be as lazy as possible)

, , :

("".join(x) for x in itertools.permutations("0123456789"))

itertools.imap , ( ), ,

+5

. , , , :

[''.join(item) for item in itertools.permutations('0123456789')]

, ( [] ()).

+1

All Articles