names = ['Kim K.S.',
'Park M.B.',
'Jo P.C.']
# List Comprehenshion
length = [len(name) for name in names]
print(length)
## [8, 9, 7]
# Dictionary Comprehenshion
length_dict = {name : len(name) for name in names}
print(length_dict)
## {'Kim K.S.' : 8, Park M.B.' : 9, 'Jo P.C.' : 7 }
'Python' 카테고리의 다른 글
[Python] Python Developer RoadMap 시작 (0) | 2023.06.28 |
---|---|
[Python] 파이썬 UUID 생성 (0) | 2023.02.09 |
[Python] 파이썬 자릿수 조절(소수점, 반올림) (0) | 2022.12.10 |
[Python] List 형태의 Dictionary 다루기 (0) | 2022.12.10 |
[Python] pandas read_exel에서 .xlsx 파일이 안 열릴 때 (0) | 2022.10.23 |