Getting all possible combinations of list items

Greg Krohn volucris at hotmail.com
Mon Sep 17 01:26:40 EDT 2001


Does anyone know of how I should go about generating a list whose keys are
all the possible combinations of the items in another list?
e.g.

another_list = ['a', 'b', 'c']

magic_algorithm(another_list) -> ['aa', 'ab', 'ac', 'ba', 'bc', 'bc', 'ca',
'cb', 'cc']

I know I could do this easily with nested 'fors', but that requires me to
know the length of the set. Is this a case for recursive functions? I hope
not, those things scare me. BTW, each item in another_list will be unique,
if that matters.

thanks for any ideas, suggestion, or urls
greg

--

Volucris (a) hotmail.com
"Eu não falo uma única palavra do português."






More information about the Python-list mailing list