Which itertools generator doesn't skip any combinations?

后端 未结 1 2031
予麋鹿
予麋鹿 2020-12-22 03:25

When I run this code I don\'t get all the possible combinations of 3 characters:

def comb(iterable, r):
    pool = tuple(iterable)
    n = len(pool)
    for          


        
相关标签:
1条回答
  • 2020-12-22 04:06

    You're looking for itertools.product(characters, repeat = 3).

    See the itertools.product docs.

    >>> ' '.join(''.join(x) for x in itertools.product('abcd', repeat = 2))
    aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd
    
    0 讨论(0)
提交回复
热议问题