하다보니

[Python] 딕셔너리 본문

프로그래밍 언어/Python

[Python] 딕셔너리

claire 2022. 7. 5. 17:35

- 딕셔너리의 키, 값 쌍 얻기 items()

딕셔너리는 items() 함수를 통해 딕셔너리에 있는 키와 값들의 쌍을 얻을 수 있다. 

keys(), values()로 각각 키와 값을 가져올 수 있다. 

a={'a':1,'b':2,'c':3}
print(a.keys())		//dict_keys(['a', 'b', 'c']) 이것을 리스트로 가져오고 싶다면 list()로 감싸줘야함


a={'a':1,'b':2,'c':3}
print(a.values())	//dict_values([1, 2, 3]) 얘도 keys와 마찬가지


print(a.items())	//dict_items([('a', 1), ('b', 2), ('c', 3)])

- 딕셔너리 정렬

https://ddolcat.tistory.com/677

'프로그래밍 언어 > Python' 카테고리의 다른 글

[Python]함수에 배열을 인자로 전달  (0) 2022.07.12
[Python]reduce  (0) 2022.07.05
코테를 위한 Python 정리  (0) 2022.05.07
[Python] set  (0) 2022.04.25
collections.defaultdict 사용법  (0) 2022.04.25