4

I have a list of dictionaries. Looks like this:

[{'direction': 'PLACE_A', 
    'line': 'S2', 
    'delay': 0, 
    'when': '2017-11-29T17:48:00+01:00', 
    'trip': 33738
    }

{'direction': 'PLACE_A', 
    'line': 'S2', 
    'delay': 0, 
    'when': '2017-11-29T17:48:00+01:00', 
    'trip': 33738
}
{'direction': 'PLACE_B', 
    'line': 'S1', 
    'delay': 0, 
    'when': '2017-11-29T17:51:00+01:00', 
    'trip': 33739
}
{'direction': 'PLACE_B', 
    'line': 'S1', 
    'delay': 0, 
    'when': '2017-11-29T17:55:00+01:00', 
    'trip': 33740
}
{'direction': 'PLACE_A', 
    'line': 'S2', 
    'delay': 0, 
    'when': '2017-11-29T17:48:00+01:00', 
    'trip': 33738
}]

Some of the entries appear twice or more: The value for trip is identical.

How can I reduce the list in a way that recurrent entries in the list of dictionaries are deleted? I tried something with set, but that didn't work here.

I appreciate any help. Thanks!

hildwin
  • 95
  • 1
  • 1
  • 5

1 Answers1

0

Just create a new list:

newlist = []
for item in oldlist:
    if item not in newlist:
        newlist.append(item)
Pulsar
  • 288
  • 1
  • 5