0
我使用Python 2.7 我的問題是一樣的python list of dictionaries find duplicates based on value 除了我我的唯一標識符基於多個鍵(ID,姓名,地址等)蟒蛇找到重複的詞典中的列表和合並
而且,基於這些鍵我必須合併一些其他值
任何建議?
謝謝
我使用Python 2.7 我的問題是一樣的python list of dictionaries find duplicates based on value 除了我我的唯一標識符基於多個鍵(ID,姓名,地址等)蟒蛇找到重複的詞典中的列表和合並
而且,基於這些鍵我必須合併一些其他值
任何建議?
謝謝
那麼一點點的幫助,我得到了這段代碼
uq_map = {}
for rec in outputs:
#Set values that are marked as unique identifiers
key = rec["o_date"], rec["o_hour"], rec["co_name"], rec["o_student"], rec["o_class"], rec["o_day"]
#If they exist we append them to a new defined key
if key in uq_map:
item = uq_map[key]
print "item ",item
item['o_teacher_set'].append(rec["o_teacher"])
item['o_location_set'].append(rec["o_location"])
#if not we insert them into new key
else:
item = rec.copy()
item['o_teacher_set'] = [rec["o_teacher"]]
item['o_location_set'] = [rec["o_location"]]
uq_map[key] = item
print uq_map
#This is the loop to remove duplicates from nwe keys
for rec in uq_map.values():
print 'Teachers: ', '+'.join(set(rec['o_teacher_set']))
如果有任何更Python solutons請讓我知道
謝謝 問候