사전 값이 개수가있는 고유 목록 인 출력을 얻으려고 노력하고 있습니다.파이썬 사전에서 고유 목록 수 얻기
여기event = [{'1a': ['tv', 'energy star tv']}, {'2a':['tv', 'energy star tv']}, {'3a':['tv', 'brand']}]
내 원하는 출력 :
여기{'tv': ['energy star tv', 2],['brand', 1]}
내 현재 코드이다 : 여기
event = [{'1a': ['tv', 'energy star tv']}, {'2a':['tv', 'energy star tv']}, {'3a':['tv', 'brand']}]
event_values = []
for e in event:
event_values.append(e.values())
e_dict = {}
for e in event_values:
if 'tv' == e[0][0]:
new_key = ''
new_key = e[0][0]
new_facet_value = ''
new_facet_value = e[0][1]
if new_key not in e_dict: # detects first key is not in dict
e_dict[new_key] = [new_facet_value, 1]
else:
i = e_dict[new_key][1] + 1 # increments count
j = []
j = [new_facet_value, i]
e_dict[new_key] = j
print e_dict
이 (원하지 않는) 내 전류 여기
내 입력 데이터 인 출력 :{'tv': ['brand', 3]}