반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Github
- c#
- gas
- PANDAS
- array
- django
- hive
- Apache
- string
- Excel
- math
- numpy
- Kotlin
- list
- Mac
- Java
- matplotlib
- GIT
- Redshift
- Google Spreadsheet
- Tkinter
- 파이썬
- google apps script
- dataframe
- Python
- Google Excel
- SQL
- PySpark
- PostgreSQL
Archives
- Today
- Total
목록기본값 dictionary (1)
달나라 노트
Python collections : defaultdict (default값이 있는 dictionary)
collections module의 defaultdict를 이용하면 default값이 있는 dictionary를 생성할 수 있습니다. 이게 무슨 말인지 예시를 통해 알아봅시다. dict_1 = { 'a': 1, 'b': 2 } print(dict_1['c']) -- Result NameError: name 'c' is not defined 위 예시에선 dictionary에 존재하지 않는 key인 c를 참조하려고 하니 NameError가 발생합니다. 당연한 얘기이겠죠. import collections def default_factory(): return 'no_data' dict_2 = collections.defaultdict(default_factory, a=1, b=2) print(dict_2) p..
Python/Python ETC
2021. 7. 15. 01:08