0

I have a list of lists like this:

elements = [
    ['keyword', 2, 5, 'fruit', 'country'],
    ['keyword2', 4, 6, 'fruit', 'country'],
    ['keyword3', 3, 5, 'fruit', 'country'],
    ['keyword', 1, 4, 'fruit', 'country']
]

I want to find duplicates in the list, but only comparing sublists items 0, 3 and 4 (keyword, fruit, country). In the above case, sublist 0 and 3 have the same items (keyword, fruit and country), so I need the script to recognize them as duplicates.

If I use in, it recognizes all of them as different because of the item 1 and 2:

elementList = []
for item in elements:
    if item not in elementList:
        elementList.append(item)

But it compares all elements of the list, and find them different.

How can I do this correctly?

mkrieger1
  • 14,486
  • 4
  • 43
  • 54

0 Answers0