472,952 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 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 1619
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Narendra C. Tulpule | last post by:
Hi, if you know the Python internals, here is a newbie question for you. If I have a list with 100 elements, each element being a long string, is it more efficient to maintain it as a dictionary...
11
by: Amy G | last post by:
I have received such good help on this message board. I wonder if I might not get a little more help from you on this. I am at the point where I have two dictionaries, with information of a...
1
by: Gabriel B. | last post by:
I just sent an email asking for hints on how to import data into a python program As i said earlier i'm really new to python and besides being confortable with the syntax, i'm not sure if i'm on...
9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
9
by: SMB | last post by:
I have two lists of data like the following: LIST1 , ] LIST2 , 'label': 'First Name', 'width': 0L, 'separator': ',', 'height': 0L, 'type': 2L, 'order': 1L}, {'code': 14L, 'name': 'Last...
4
by: Branka | last post by:
Hi I have 20 'for' loops to create more than 40 million variations with repetitions. More precisely: I have total of nine factors with three possible levels (3^9) and 11 factors with 2 possible...
15
by: Gigs_ | last post by:
Hi all! I have text file (english-croatian dictionary) with words in it in alphabetical order. This file contains 179999 words in this format: english word: croatian word I want to make...
6
by: pj | last post by:
Hi, I 'm currently writing a program that performs transliteration (i.e., converts greek text written using the english alphabet to "pure" greek text using the greek alphabet) as part of my...
3
by: ELK | last post by:
I recently started a beginners programming course and am struggling with my latest assignment. I have been given a .txt file of the results of a relay race with the following columns of data: team...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.