반응형
zip()
두개의 iterable한 자료형을 각각의 튜플로 바꿔주는 함수!
a = [1,2,3]
b = 'abc'
c = list(zip(a,b))
print(c)
....................
[(1, 'a'), (2, 'b'), (3, 'c')]
이걸 이용해서 dictionary 자료형으로 편하게 만들수도 있다.
a = [1,2,3]
b = 'abc'
c = dict(zip(a,b)
print(c)
............
{1: 'a', 2: 'b', 3: 'c'}
조합 구하는 함수(combinations(),permutations(),product())
https://ourcstory.tistory.com/414
파이썬(Python) 리스트 모든 조합 구하기 (combination vs permutations vs product)
파이썬 (Python)에서 리스트에 있는 값들의 모든 조합을 구하기 파이썬에서 리스트에 있는 값들의 모든 조합을 구하기 위해서는 여러가지 방법이 있다. 파이썬 기본 라이브러리인 itertools을 사용
ourcstory.tistory.com
단일 리스트 안 자료들 조합 구할때
-combinations(),permutations()
a = [1,2,3]
list(combinations(a, 2))
................................
[(1,2)(1,3)(2,3)]
복수 리스트 안 자료들 같이 조합 구할때
-product()
a = [[1,2],['a','b']]
list(product(*items))
..............
[(1,a),(1,b),(2,a),(2,b)]
반응형
'과거의 유산들 > python' 카테고리의 다른 글
index(),find(),count()와 시간복잡도 (0) | 2022.08.07 |
---|---|
큐 list or Deque (0) | 2022.08.04 |
정규식 (0) | 2022.07.29 |
for a,b in 이중 리스트 (0) | 2022.07.17 |
파이썬 fstring,문자와 데이터 같이 넣기 (0) | 2022.06.28 |