티스토리 뷰

0. python from itertools import product

- 길이 3이니깐 3^2 = 9 

- 길이는 9개 

- 두개 이상의 리스트에서 모든 조합을 구하는 방법 

1
2
3
4
5
6
7
from itertools import product
example = [['x'],['a','b',],['1','2','3']]
result = list(product(example, example))
len_result = len(result)
print(result)
#[(['x'], ['x']), (['x'], ['a', 'b']), (['x'], ['1', '2', '3']), (['a', 'b'], ['x']), (['a', 'b'], ['a', 'b']), (['a', 'b'], ['1', '2', '3']), (['1', '2', '3'], ['x']), (['1', '2', '3'], ['a', 'b']), (['1', '2', '3'], ['1', '2', '3'])]
print(len_result)  #9 
cs

'Programming > python' 카테고리의 다른 글

파이썬 - 파이썬을 파이썬답게  (0) 2020.04.09
python - pandas [3] groupby  (0) 2019.10.07
python 멀티 프로세스와 멀티 스레드  (0) 2019.10.05
python hashlib  (0) 2019.10.04
python partial 함수와 lambda 함수  (0) 2019.10.04
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함