I need to get at a value in a list of lists. The list in question is called 'newdetails'. It's contents are below
[['12345670', 'Iphone 9.0', '500', '5', '3', '5'], ['12121212', 'Samsung Laptop', '900', '5', '3', '5']]
I found that print(newdetails[0]) prints the entire first list. What I need however, is to get at index[0] of the first list which is 12345670. I also need to replace index 03 (of both lists) with the VALUE in a dictionary, which corresponds to the first GTIN number.
the code I have so far is:
for gtin,currentstock in dictionary.items():
if newdetails[0]==gtin:
newdetails[3]=currentstock
print("checking to see what newdetails[0] and [3] and [9] is")
print(newdetails[0])
print("or is it a matrix or a 2d array")
print(newdetails[0,3])
print("now will this work...print replacement list")
print(newdetails)
Can someone help?
UPDATE:
Thank you for your suggestion. I tried this: (but it came up with an error)
for sub_list in newdetails:
sub_list[3] = dictionary(sub_list[3], sub_list[3])
print("sublist")
print(sub_list)
Error: sub_list[3] = dictionary(sub_list[3], sub_list[3]) TypeError: 'dict' object is not callable
To clarify, the list i have is called 'newdetails' - and it has two lists inside it (read in from a file). The name of the dictionary is simply dictionary (for now), and it has a GTIN key and a 'currentstock' VALUE. I want the GTIN key in the dictionary that corresponds with the same GTIN value in BOTH lists to update index 3 (currently showing as 5),. with the value 'currentstock' in the dictionary, that corresponds to the GTIN number.
Thanks in advance to the helpful genius who can help me solve this!