It's hard to tell without code but if I have to guess then along the road you sorted cows dictionary (row #12 in original code) and got list of tuples and then used for-loop with enumerate (row #14 where name 'key' means indice and 'value' means tuple in list) and then tried to add to said tuple:
>>> d = {'Maggie': 3, 'Herman': 7, 'Betsy': 9, 'Oreo': 6, 'Moo Moo': 3, 'Milkshake': 2, ... 'Millie': 5, 'Lola': 2, 'Florence': 2, 'Henrietta': 9} >>> sorted(d.items()) [('Betsy', 9), ('Florence', 2), ('Henrietta', 9), ('Herman', 7), ('Lola', 2), ('Maggie', 3), ('Milkshake', 2), ('Millie', 5), ('Moo Moo', 3), ('Oreo', 6)] >>> for key, value in enumerate(sorted(d.items())): ... print(key, value) ... 0 ('Betsy', 9) 1 ('Florence', 2) 2 ('Henrietta', 9) 3 ('Herman', 7) 4 ('Lola', 2) 5 ('Maggie', 3) 6 ('Milkshake', 2) 7 ('Millie', 5) 8 ('Moo Moo', 3) 9 ('Oreo', 6)Regarding combinations with dictionaries - it's can be achieved quite easily. Below there is step-by-step approach (which can be condensed if required):
>>> d = {'Maggie': 3, 'Herman': 7, 'Betsy': 9, 'Oreo': 6, 'Moo Moo': 3, 'Milkshake': 2, ... 'Millie': 5, 'Lola': 2, 'Florence': 2, 'Henrietta': 9} >>> combs = ({j: d[j] for j in i} for i in combinations(d, 2)) # generator of dictionaries to yield all pair combinations >>> qualifying = (row for row in combs if sum(row.values()) < 10) # generator to yield those pairs which weight is less than 10 >>> sorted(qualifying, key=lambda x: sum(x.values()), reverse=True) # consuming piped generators and getting sorted list of dictionaries [{'Maggie': 3, 'Oreo': 6}, {'Herman': 7, 'Milkshake': 2}, {'Herman': 7, 'Lola': 2}, {'Herman': 7, 'Florence': 2}, {'Oreo': 6, 'Moo Moo': 3}, {'Maggie': 3, 'Millie': 5}, {'Oreo': 6, 'Milkshake': 2}, {'Oreo': 6, 'Lola': 2}, {'Oreo': 6, 'Florence': 2}, {'Moo Moo': 3, 'Millie': 5}, {'Milkshake': 2, 'Millie': 5}, {'Millie': 5, 'Lola': 2}, {'Millie': 5, 'Florence': 2}, {'Maggie': 3, 'Moo Moo': 3}, {'Maggie': 3, 'Milkshake': 2}, {'Maggie': 3, 'Lola': 2}, {'Maggie': 3, 'Florence': 2}, {'Moo Moo': 3, 'Milkshake': 2}, {'Moo Moo': 3, 'Lola': 2}, {'Moo Moo': 3, 'Florence': 2}, {'Milkshake': 2, 'Lola': 2}, {'Milkshake': 2, 'Florence': 2}, {'Lola': 2, 'Florence': 2}]If you look closely you can observe, that there are missing cows in dictionary as Henriette and Betsy are too heavy to make into pair. Of course there are repetitions as well.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.