-3
[
    {'date': '08/11/2016', 'duration': 13.0}, 
    {'date': '08/17/2016', 'duration': 5.0}, 
    {'date': '08/01/2016', 'duration': 5.2}, 
    {'date': '08/11/2016', 'duration': 13.0}, 
    {'date': '08/11/2016', 'duration': 13.0}, 
    {'date': '08/11/2016', 'duration': 13.0}
]

if data is like that.

PM 2Ring
  • 54,345
  • 6
  • 82
  • 182
Gaurav Kumar
  • 241
  • 1
  • 4
  • 12
  • 4
    Please show what you have done yourself. Read how to put together a [mcve] to help guide you. – idjaw Aug 29 '16 at 12:23

2 Answers2

2

One easy but not really efficient solution can be:

a = [{'date': '08/11/2016', 'duration': 13.0}, {'date': '08/17/2016', 'duration': 5.0}, {'date': '08/01/2016', 'duration': 5.2}, {'date': '08/11/2016', 'duration': 13.0}, {'date': '08/11/2016', 'duration': 13.0}, {'date': '08/11/2016', 'duration': 13.0}]
b = []
for c in a:
   if c in b:
      continue
   b.append(c)
print(b)
Xavier C.
  • 1,921
  • 15
  • 22
0

One way is to use FrozenDict. By using this, you may perform set like operation on your dict. But this not available as default python package.

Alternatively, Make entry from your list to new list and make a check before entering the new value. Below is the sample code:

my_list = [{'date': '08/11/2016', 'duration': 13.0}, {'date': '08/17/2016', 'duration': 5.0}, {'date': '08/01/2016', 'duration': 5.2}, {'date': '08/11/2016', 'duration': 13.0}, {'date': '08/11/2016', 'duration': 13.0}, {'date': '08/11/2016', 'duration': 13.0}]

new_list = []
for item in my_list:
    if item not in new_list:
        new_list.append(item)

# new_list = [{'date': '08/11/2016', 'duration': 13.0}, {'date': '08/17/2016', 'duration': 5.0}, {'date': '08/01/2016', 'duration': 5.2}]
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126