May-04-2018, 12:24 PM
hello, im a newbie, been digging around to find a solution to a problem for the creation of a complex structure using itertools - permutation combination.
So far i've been using
e.g i have n number of list and i want to see all the possible outcomes, where the outcome is taken from 3 lists
list01: 01,02,03,04,05
list02: 01,03,07,10
list03: 02,03,06,08,09
list04: 01,03,05,06,07
outcome : [a,b,c], [a,d,e], [a,f]
for e.g,
[a,b,c] is taken from a list01
[a,d,e] is taken from list02, and
[a,f] is taken from list03
basically, the outcome needs to be validated, for e.g [a] is present across the 3 lists, [b,c,d,e,f] is unique in a way [if b is choosen in list01, it cannot be choosen in list02...
1 possible outcome could be [01,02,03],[03,07,10],[03,06], under list01/02/03/
what im tryin to accomplish is to run a permutation across n number of list, 3 combinations, then further create the outcome : [a,b,c], [a,d,e], [a,f]
[/quote]
So far i've been using
from itertools import product, combinations, combinations_with_replacement
to acheive the basic stuff. But i want to create something else and i don't know where to start. Ok, so im going to copy paste my question from stackflow:from itertools import product, combinations, combinations_with_replacement flavors = ["chocolate", "vanilla", "strawberry", "coffee"] sizes = ["small", "medium", "large"] toppings = ["sprinkles", "gummy bears", "oreos", "cookie dough", "snickers", "brownies"] syrups = ["hot fudge", "caramel", "strawberry", "white chocolate"] # # pick a flavor and a size for flavor,size in product(flavors, sizes): # # pick three toppings, but no more than one of each for top_a, top_b, top_c in combinations(toppings, 3): # # pick three syrups, allowing repeats for syr_a, syr_b, syr_c in combinations_with_replacement(syrups, 3): # # now do something with the result: print(", ".join([flavor, size, top_a, top_b, top_c, syr_a, syr_b, syr_c]))in this example itertools is used to print all possible outcomes,easy as 123. Been digging 16hrs a day for the past couple days, to built a much more complex structure with arguments and parameters [algorithms], and i'm struggling to find my way trough
e.g i have n number of list and i want to see all the possible outcomes, where the outcome is taken from 3 lists
list01: 01,02,03,04,05
list02: 01,03,07,10
list03: 02,03,06,08,09
list04: 01,03,05,06,07
outcome : [a,b,c], [a,d,e], [a,f]
for e.g,
[a,b,c] is taken from a list01
[a,d,e] is taken from list02, and
[a,f] is taken from list03
basically, the outcome needs to be validated, for e.g [a] is present across the 3 lists, [b,c,d,e,f] is unique in a way [if b is choosen in list01, it cannot be choosen in list02...
1 possible outcome could be [01,02,03],[03,07,10],[03,06], under list01/02/03/
what im tryin to accomplish is to run a permutation across n number of list, 3 combinations, then further create the outcome : [a,b,c], [a,d,e], [a,f]
[/quote]