Compare two lists with index
def compare(A,B):
for i in range(len(A)):
if B[A.index(B[i])]==A[i]:
return True
print(B[A.index(B[i])],A[i]) # print to understand more
return False
Note
If the two lists don't have similar letters, this won't work, since it refers to the letters.
How to compare the index of 2 sublists' elements from a list of lists
Your indexing is not correct in general.
Try something like the following:
for i in range(1,len(R_list)):
if R_list[i][0]!=R_list[i-1][0]:
R_list[i].append(0)
else:
R_list[i].append(int(R_list[i][1])+int(R_list[i-1][1]))
For
R_list = [['1046', '10', 0], ['1047', '12', 0], ['1047', '12', 0]]
the above gives:
[['1046', '10', 0], ['1047', '12', 0, 0], ['1047', '12', 0, 24]]
Related Topics
A Way to Quick Preview .Ipynb Files
How to Create Different Variable Names While in a Loop
How to Determine Whether a Pandas Column Contains a Particular Value
How to Remove Empty Cell from Data Frame Row Wise
How to Save a Pandas Dataframe Table as a Png
How to Find 3 Immediate Words After Keyword Match Using Python
Calculating the Area Under a Curve Given a Set of Coordinates, Without Knowing the Function
Decode Utf-8 Encoding in Json String
How to Convert Strings With Billion or Million Abbreviation into Integers in a List
Python Json.Loads Valueerror, Expecting Delimiter
Programme to Print Mulitples of 5 in a Range Specified by User
How to Get the Response Json Data from Network Call in Xhr Using Python Selenium Web Driver Chorme
Find the Index of a Value in a 2D Array
How to Convert a 1 Channel Image into a 3 Channel With Opencv2