gpt4 book ai didi

列表上的 Python 分配属性

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

我有以下情况:List[i][j] 如下所示:

 [['Motorized', 'Motorize', 'Motoriz', 'Motori', 'Motor', 'Moto', 'Mot', 'Mo', 'M'],
['wheel', 'whee', 'whe', 'wh', 'w'],
['chair', 'chai', 'cha', 'ch', 'c']]

我想尽可能组合所有订单中的所有值,例如:

Motorized wheel chair, M wheel c, ...

是否有内置函数可以执行此操作?关于该列表可以有任何维度。

最佳答案

这就是itertools.product用于:

lst = [['Motorized', ...] ... ]
for combination in itertools.product(*lst):
print ' '.join(combination)

关于列表上的 Python 分配属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35415911/

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