반응형
3 차원 튜플을 배열로 변환하는 방법
a = []
a.append((1,2,4))
a.append((2,3,4))
다음과 같은 배열 :
b = [1,2,4,2,3,4]
해결 방법
>>> a = []
>>> a.append((1,2,4))
>>> a.append((2,3,4))
>>> [x for xs in a for x in xs]
[1, 2, 4, 2, 3, 4]
>>> import itertools
>>> list(itertools.chain.from_iterable(a))
[1, 2, 4, 2, 3, 4]
참조 페이지 https://stackoverflow.com/questions/20637970
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python PIL NameError 전역 이름 이미지가 정의되지 않았습니다. (0) | 2020.12.27 |
---|---|
파이썬 How to use 2to3 properly for python? (0) | 2020.12.27 |
파이썬 Square of each element of a column in pandas (0) | 2020.12.27 |
파이썬 클래스 속성과 인스턴스 속성의 차이점은 무엇입니까? (0) | 2020.12.27 |
파이썬 Subtracting two lists in Python (0) | 2020.12.27 |
댓글