I am trying to print the common items in two list of lists with different sizes, but I am getting the following error. TypeError: 'int' object is not subscriptable
These are the lists
lst1 = [[1234, John Paul, New York], [4567, Jude Law, London],[7891, Rick Ross, Miami]]
lst2 = [[1234, John Paul, New York], [7891, Rick Ross, Miami]]
This is my function which is looping through the list and trying to find the common items and put them into a new list.
lst1 = [[1234, John Paul, New York], [4567, Jude Law, London],[7891, Rick Ross, Miami]]
lst2 = [[1234, John Paul, New York], [7891, Rick Ross, Miami]]
list = []
min_lengh = min(len(lst1), len(lst2))
max_lengh = max(len(lst1), len(lst2))
for i in range(max_lengh):
if lst1[i[0] % min_lengh] == lst2[i[0] % min_lengh]:
list.append(i % min_lengh)
return list
So I am checking if the first items in the list match, if they do then add them to the list.
The line which is throwing the error is this.
if lst1[i[0] % min_lengh] == lst2[i[0] % min_lengh]:
What am I doing wrong?