need a variation algorithm for Lists in Dictionaries
Paddy
paddy3118 at googlemail.com
Thu Jul 5 01:47:53 EDT 2007
On Jul 5, 3:58 am, "Marc Stuart" <marc.stuart.ris... at gmail.com> wrote:
> Hi, I am trying to create a function, where I pass a dictionary with a
> lits of strings, and try to return a
> a list of strings, for all variations, any ideas ?
> Thanks
>
> def getAllVariants(someDict):
> keys = someDict.keys()
> for x in keys:
> print len(someDict[x])
>
> x = {1:['a','b'],2:['b','c'],3:['d','e','f','g']}
> getAllVariants(x)
>
> """ I need to get a list of strings that render all possible variants,
> this is what my output should be based on the
> x dictionary:
> abd
> abe
> abf
> acd
> ace
> acf
> acg
> bbd
> bbe
> bbf
> bcd
> bce
> bcf
> bcg
>
> """
Here's two possibilities:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502199
http://jace.seacrow.com/archive/2007/02/15/generating-combinations-in-python
- Paddy.
More information about the Python-list
mailing list