이 기사에서는 Python 3.x에서 사전의 반복/순회에 대해 배웁니다. 또는 그 이전.
사전은 키-값 쌍의 순서가 지정되지 않은 시퀀스입니다. 인덱스는 변경할 수 없는 모든 유형이 될 수 있으며 키라고 합니다. 이것은 중괄호 안에도 지정됩니다.
방법 1 - iterable을 직접 사용
예시
dict_inp = {'t':'u','t':'o','r':'i','a':'l','s':'p','o':'i','n':'t'}
# Iterate over the string
for value in dict_inp:
print(value, end='') 출력
trason
방법 2 - 사전 값에 대해 이터러블 사용
예시
dict_inp = {'t':'u','t':'o','r':'i','a':'l','s':'p','o':'i','n':'t'}
# Iterate over the string
for value in dict_inp.values():
print(value, end='') 출력
oilpit
방법 3 - 키를 인덱스로 사용
예시
dict_inp = {'t':'u','t':'o','r':'i','a':'l','s':'p','o':'i','n':'t'}
# Iterate over the string
for value in dict_inp:
print(dict_inp[value], end='') 출력
oilpit
방법 4 - 사전의 키와 값 사용
예시
dict_inp = {'t':'u','t':'o','r':'i','a':'l','s':'p','o':'i','n':'t'}
# Iterate over the string
for value,char in dict_inp.items():
print(value,":",char, end=" ") 출력
t : o r : i a : l s : p o : i n : t
결론
이 기사에서 우리는 Python의 사전에 대한 반복/순회에 대해 배웠습니다.