"파이썬 defaultdict"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;파이썬 defaultdict
;파이썬 defaultdict
<source lang='python'>
<source lang='python'run>
from collections import defaultdict
from collections import defaultdict
dd = defaultdict(lambda: 'hello')
dd = defaultdict(lambda: 'hello')

2020년 2월 29일 (토) 11:28 판

1 개요

파이썬 defaultdict
from collections import defaultdict
dd = defaultdict(lambda: 'hello')
dd['Alice'] = 'apple'
dd['Bob'] = 'banana'
print( dd['Alice'] )
# apple
print( dd['Bob'] )
# banana
print( dd['Carol'] )
# hello
print( dd['John'] )
# hello

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}