회원 로그인
|
list형을 dictionary형으로 형변환
리스트형를 사전형으로 변환
참고
https://stackoverflow.com/questions/4576115/convert-a-list-to-a-dictionary-in-python
https://stackoverflow.com/questions/209840/map-two-lists-into-a-dictionary-in-python
#질의 a = ['hello','world','1','2'] #을 사전형으로 #요렇게 #{'1': '2', 'hello': 'world'} #해답 b = dict(zip(a[::2], a[1::2])) #or from itertools import izip i = iter(a) b = dict(izip(i, i)) #or b = {a[i]: a[i+1] for i in range(0, len(a), 2)} #or i = iter(a) b = dict(zip(i, i)) #두개의 리스트형을 사전형으로 형변환 keys = ['a', 'b', 'c'] values = [1, 2, 3] dictionary = dict(zip(keys, values)) #결과 #{'a': 1, 'b': 2, 'c': 3}
참고
https://stackoverflow.com/questions/4576115/convert-a-list-to-a-dictionary-in-python
https://stackoverflow.com/questions/209840/map-two-lists-into-a-dictionary-in-python
댓글 0개
| 엮인글 0개
285개(4/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
225 | [Swift] Creating Face-Based AR Experiences | 푸딩뱃살 | 1813 | 2018.09.04 11:01 |
224 | [Python] qt4 progressbar 예제 | 푸딩뱃살 | 2910 | 2018.08.25 13:18 |
223 | [Java] JavaScript 기초 | 푸딩뱃살 | 1123 | 2018.08.19 17:09 |
222 | [PHP] echo와 print_r 차이점 | 푸딩뱃살 | 2531 | 2018.05.19 03:10 |
221 | [Python] 파이썬 GC(Garbage Collection) | 푸딩뱃살 | 2431 | 2018.04.25 15:47 |
220 | [Python] if __name__ == '__main__': | 푸딩뱃살 | 2668 | 2018.04.16 17:52 |
219 | [Python] 삼항 조건 연산자 (Ternary Operator) | 푸딩뱃살 | 2373 | 2018.04.16 17:41 |
218 | [Python] Non-ASCII character 에러 | 푸딩뱃살 | 3079 | 2018.04.16 16:49 |
217 | [VisualStudio] Visual Studio Community 설치 파일 (다운로드형) | 푸딩뱃살 | 2445 | 2018.04.10 09:54 |
216 | [Python] QProgressBar Stylesheet | 푸딩뱃살 | 3073 | 2018.03.20 15:15 |
215 | [Python] 컨커런시(Concurrency) | 푸딩뱃살 | 3664 | 2018.03.14 12:36 |
214 | [Python] 데코레이터(Decorator) @ | 푸딩뱃살 | 2375 | 2018.03.14 11:09 |
213 | [Python] os.environ | 푸딩뱃살 | 2212 | 2018.03.02 18:05 |
212 | [Python] A QApplication instance already exists. | 푸딩뱃살 | 2774 | 2018.02.21 16:44 |
211 | [Python] pyuic5 사용 for Maya | 푸딩뱃살 | 3364 | 2018.02.21 12:28 |
210 | [Qt] Qt Training - Qt Essentials Self-Study Pack | 푸딩뱃살 | 1684 | 2018.01.24 18:07 |
>> | [Python] list형을 dictionary형으로 형변환 | 푸딩뱃살 | 5709 | 2018.01.22 18:08 |
208 | [Python] 개발 가상 환경을 위한 virtualenv | 푸딩뱃살 | 2548 | 2017.12.26 15:22 |
207 | [Python] Qt.py .ui파일 불러오기 | 푸딩뱃살 | 2606 | 2017.11.09 17:15 |
206 | [Python] 환경 변수 추가 | 푸딩뱃살 | 2092 | 2017.11.09 17:10 |