I have some very inefficient code I'd like to make more general/efficient. I am trying to create strings from a set of lists.
Here is what I currently have:
#contains categories
numind = [('Length',), ('Fungus',)]
#contains values that pertain to the categories
records = [('Length', 'Long'), ('Length', 'Med'), ('Fungus', 'Yes'), ('Fungus', 'No')]
#contains every combination of values between the 2 categories.
#for example, (Long, Yes) = Length=Long & Fungus = Yes.
combinations = [('Long', 'Yes'), ('Long', 'No'), ('Med', 'Yes'), ('Med', 'No')]
Now I want to create strings that have every combination in my combination list. This is the inefficient part. I'd like it so that I don't have to hardwire the length of the "numind" list. Any ideas?
values = combinations
valuestring = []
if len(numind) == 0:
pass
elif len(numind) == 1:
for a in xrange(len(values)):
valuestring.append(numind[0][0]+values[a][0])
elif len(numind) == 2:
for a in xrange(len(values)):
valuestring.append(numind[0][0]+values[a][0]+'_'+numind[1][0]+values[a][1])
#and so forth until numind is 10+
output
['LengthLong_FungusYes', 'LengthLong_FungusNo', 'LengthMed_FungusYes', 'LengthMed_FungusNo']