Created
May 17, 2021 19:28
-
-
Save simse/4d2959e1bc974a15c1e0f89a6f74175f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list of lists, length is not capped | |
options = [ | |
["Italian", "9-Grain Wheat"], # Bread | |
["American", "Swiss", "Cheddar"], # Cheese | |
["Ranch", "Mayo", "BBQ", "Ketchup", "Thousand Island"], # Sauce | |
["Honey Mustard", "Plain"] # Ham | |
] | |
def multiply_list(options, results_input=[]): | |
# base case | |
if len(options) == 0: | |
return results_input | |
# temp list | |
resulting_list = [] | |
# loop through options in first list | |
for i in options.pop(0): | |
# if first iteration, init list of lists | |
if results_input == []: | |
resulting_list.append([i]) | |
# otherwise start appending | |
else: | |
# for each combination already made, add next layer | |
for j in results_input: | |
resulting_list.append(j + [i]) | |
# repeat (WAH RECURSION) | |
return multiply_list(options, resulting_list) | |
multiply_list(options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment