1. 程式人生 > >python 刪除重複元素字典並在字典中加入重複元素次數

python 刪除重複元素字典並在字典中加入重複元素次數

mylist = [{"b":1},{"b":1},{"b":1},{"b":1},{"c":2},{"c":2},{"b":1},{"b":1},{"b":1},{"c":2},{"c":2}]
myset = []
for i in mylist:
    if not i in myset:
        myset.append(i)
print myset
for item2 in myset:
    c = mylist.count(item2)
    item2['count'] = c
print myset