471,354 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

need a variation algorithm for Lists in Dictionaries

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

"""
Jul 5 '07 #1
1 1575
On Jul 5, 3:58 am, "Marc Stuart" <marc.stuart.ris...@gmail.comwrote:
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/Coo.../Recipe/502199
http://jace.seacrow.com/archive/2007...ions-in-python

- Paddy.

Jul 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Narendra C. Tulpule | last post: by
1 post views Thread by Gabriel B. | last post: by
9 posts views Thread by Dave H | last post: by
9 posts views Thread by SMB | last post: by
4 posts views Thread by Branka | last post: by
15 posts views Thread by Gigs_ | last post: by
3 posts views Thread by ELK | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.