gpt4 book ai didi

python - 从python中的子序列中获取所有可能的字符串

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:37 24 4
gpt4 key购买 nike

我有这样的代码:

inp = [['6', '0', '5', '9', '8'], ['='], ['9', '0', '5', '8', '6']]

我想要这样的结果:

outp = ['6=9','0=9','5=9' ... '8=8', '8=6']

inp的大小可以不同

最佳答案

您可以使用 itertools.product:

from itertools import product
outp = list(map(''.join, product(*inp)))

outp 变成:

['6=9', '6=0', '6=5', '6=8', '6=6', '0=9', '0=0', '0=5', '0=8', '0=6', '5=9', '5=0', '5=5', '5=8', '5=6', '9=9', '9=0', '9=5', '9=8', '9=6', '8=9', '8=0', '8=5', '8=8', '8=6']

关于python - 从python中的子序列中获取所有可能的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54721193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com