Python加速了列表置换的生成(以及Dict中是否置换的检查过程)

2024-09-30 12:15:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一种更快的方法来生成列表的所有排列,然后检查每个排列是否在字典中。

        for x in range (max_combo_len, 0, -1):
            possible_combos = []
            permutations = list(itertools.permutations(bag,x))
            for item in permutations:
                possible_combos.append(" ".join(item))
            #then check to see if each possible combo is in a specific Dict

如果有帮助的话,列表都是字符串列表。['例如','这个','一']

我的解决方案有效,但速度很慢。可能我需要停止使用Python,但我想我应该先由您的专家来运行它!

最好的, 加里


Tags: 方法in列表forlen字典rangeitem

热门问题