2017-12-31 11 views
-3

나는 x, y를 가지고있다.이 [(x, y), (y, x), (x, x), (y, y)] 내가 생각하는 모든 해결책은 지나치게 불평하고 상당히 비소색 인 것 같습니다/x, y에서 만드는 파이썬 우아한 방법 모든 posibble tupples리스트

+0

이러한 솔루션에 대해 비 파이썬이 아닌 것은 무엇입니까? – wwii

+0

만약 당신이 a = [1,2]를 가지고 있다면 해답은 – mamun

+2

[in it for a j]에서 i에 대해 b = [(i, j)] (https : //docs.python. org/3/library/itertools.html # itertools.product) – BrenBarn

답변

2

무엇을 찾고 있습니까 cartesian product입니다.

Python Itertools Function:product(iterable, repeat=1) 입력 반복 가능 객체의

직교 제품.

for x in itertools.product(['x', 'y'], repeat=2): 
    print(x) 
    pass 
관련 문제