Dictionary
"키 - 값" 쌍으로 구성되며 키를 통해 값을 쉽게 찾을수 있도록 한다.
dict = {}
dict = ['key'] = 'value'
print(dict)
# {'key' : 'value'}
메서드
- keys(), values(), items()
print(dict.keys())
#
print(dict.values())
#
print(dict.items())
# [('key', 'value')]
- get()
dict["kkeeyy"]를 실행할 경우 에러가 발생한다.
print( dict.get("kkeeyy") )
# None
- update()
여러 데이터를 갱신할 때 사용한다.
dict.update({'key2' : 'value2' , 'key3' : 'value3'})
print(dict)
# {'key' : 'value' , 'key2' : 'value2' , 'key3' : 'value3'}
List
- 리스트 원소를 띄어쓰기 없이 출력하기
print(''.join(listname))
- 정렬된 리스트에서 특정 원소가 들어갈 위치 찾기
from bisect import bisect_left, bisect_right #인덱스 값을 반환한다.
l = [1,2,3,3,4,5]
bisect_left(l,3) # 2
bisect_right(l,3) # 4
bisect_right - bisect_left # 2 (원소 3의 개수)
# 데이터 결과값 예쁘게 출력
pp = pprint.PrettyPrinter(indent=4)
print(pp.pprint(contents))
'Python > Python Lib' 카테고리의 다른 글
[Numpy] 계산 (0) | 2021.01.06 |
---|---|
파이썬 : 문자열 (0) | 2021.01.02 |
파이썬 : 오류 관련 (0) | 2020.12.28 |
파이썬 : 파일 관리 및 사용 (0) | 2020.12.24 |
[Pandas] dataframe 조건에 따라 값 변경하기 (0) | 2020.08.05 |