+ 4
No problem, timezone stuff is common : )
Okay so let me get this straight now. You want to search for an ingredient (apple) in the list, and change the amount of it. I'm considering the sub-list be structured as [ingredient, amount] here, so tell me if I get it wrong.
I'd rather not discuss "clean" or not here just yet, first thing is to get the code to work as expected, then after, how to make it "cleaner".
Pantry code? sounds cool ...
+ 3
Is the code working as expected? if so, then what is the problem? Otherwise can you explain what you are trying to do, and what changes is expected to take place with the nested list.
+ 2
Kode Krasher ,
Jacob Hicks posted a solution using list.
Hence list.
+ 1
my_list = [["apple", 4], ["pear", 3], ["bread", 2]]
def item_list():
for pairs in my_list:
return pairs
pair = [['apple', 3], ["berry", 5]]
for item in pair:
if item[0] in item_list():
item_list()[1] += item[1]
else:
my_list.append(item)
print(my_list)
'''
[['apple', 7], ['pear', 3], ['bread', 2], ['berry', 5]]
[Program finished]
'''