I have a word 와 함께 20 000 구성형 엔트리입니다 순간 사전 단순히 고유해야 횟수를 단어가 사용된 소스 텍스트 (Dante& # 39 의 신곡 이탈리아).
모든 항목을 통해 실제 가치를 함께 일해 보고 싶어요 교체하십니까 정의마다 as I 것들이었다고요. 단순한 방법이 없다는 여러_키워드 반복할 수 있는 값으로 바꾸기 위해 (as I 연구 의미)?
사전 시작됩니다.
{'corse': 378, 'cielo,': 209, 'mute;': 16, 'torre,': 11, 'corsa': 53, 'assessin': 21, 'corso': 417, 'Tolomea': 21} # etc.
일종의 키워드 연구 · 정의하십시오 제안하세요 애플리케이션과는 것입니다.
(또는 유형의 값) 의 특정 값을 선택할 수 없습니다. # 39; d 할 you& 인컨텍스트 역동기화 인덱스화할 (매핑해야 숫자임 다시 (목록) 키) 또는 반복할 때마다 모든 값을 통해 얻을 수 있습니다.
어쨌든 주문하십시오 처리하는 경우, 임의의 숫자를 뿐만 아니라 모든 항목을 반복하고 있습니다.
for key, value in inputdict.items():
# do something with value
inputdict[key] = newvalue
그렇지 않으면 I&; d # 39 역동기화에 함께 가지 색인:
from collections import defaultdict
reverse = defaultdict(list)
for key, value in inputdict.items():
reverse[value].append(key)
이제 키 값으로 찾아볼 수 있습니다.
for key in reverse[value]:
inputdict[key] = newvalue
인컨텍스트 다음과 같습니다.
"'파이썬 my_dict.update ({& # 39, key1& # 39;: # 39, & # 39, & # 39 value1& key2& # 39;:;; # 39, & # 39 value2&,}) "'
또는 그런.
"'파이썬 my_dict.update (key1 = & # 39, & # 39, # 39 value2& value1& key1 = # 39;;) "'
[1]: https://docs.python.org/3/library/stdtypes.html # 딕트.업다이트
이것은 기업의 주요 고객의 가치를 찾을 수 있는 기능 및 교체.
current_dict = {'corse': 378, 'cielo': 209, 'mute': 16}
print(current_dict)
def replace_value_with_definition(key_to_find, definition):
for key in current_dict.keys():
if key == key_to_find:
current_dict[key] = definition
replace_value_with_definition('corse', 'Definition of "corse"')
print(current_dict)
출력은:
{'corse': 378, 'cielo': 209, 'mute': 16}
{'corse': 'Definition of "corse"', 'cielo': 209, 'mute': 16}
너무 길어서 루프를 통해 사전을 찾을 수 있다면 그것은 시도해보십시오 발생기입니다 기능:
def gen_replace_value_with_definition(key_to_find, definition):
for key in current_dict.keys():
if key == key_to_find:
current_dict[key] = definition
yield True
yield False
found = False
while not found:
found = next(gen_replace_value_with_definition('corse', 'Definition of "corse" via generator'))
print(current_dict)
출력:
{'corse': 'Definition of "corse" via generator', 'cielo': 209, 'mute': 16}