Skip to main content
 首页 » 编程设计

列表上的 Python 分配属性

2025年05月04日32zlslch

我有以下情况: 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)