【问题标题】:Does itertools.product really generates all possible permutations? [closed]itertools.product 真的会生成所有可能的排列吗? [关闭]
【发布时间】:2020-03-20 16:41:53
【问题描述】:

这可能是一个愚蠢的问题,但有些东西对我来说并不重要。

我的代码:

lowercase_letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
combos = list(product(lowercase_letters_ascii, repeat=3))

这将创建 15625 个组合。不应该有 17576 (26^3) 个组合吗? 我错过了什么?

谢谢

【问题讨论】:

  • “我错过了什么?”字母“j”:-)
  • 哦,太尴尬了。谢谢。
  • 请注意,Python 有一个string.ascii_lowercase

标签: python permutation product itertools


【解决方案1】:

看!

>>> len(lowercase_letters)
25
>>> 25**3
15625

通过眼球,您的列表缺少字母“j”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多