将此python代码的输出更改为列表?

将此python代码的输出更改为列表?,python,Python,下面的python代码给出了与给定值不同的组合 import itertools iterables = [ [1,2,3,4], [88,99], ['a','b'] ] for t in itertools.product(*iterables): print t 输出:- (1, 88, 'a') (1, 88, 'b') (1, 99, 'a') (1, 99, 'b') (2, 88, 'a') 等等 有人能告诉我如何修改这个代码,使输出看起来像一个列表 188a 188

下面的python代码给出了与给定值不同的组合

import itertools

iterables = [ [1,2,3,4], [88,99], ['a','b'] ]
for t in itertools.product(*iterables):
    print t
输出:-

(1, 88, 'a')
(1, 88, 'b')
(1, 99, 'a')
(1, 99, 'b')
(2, 88, 'a')
等等

有人能告诉我如何修改这个代码,使输出看起来像一个列表

188a
188b
199a
199b
288a
您可以尝试以下方法:

iterables = [ [1,2,3,4], [88,99], ['a','b'] ]

new_list = [''.join(map(str, i)) for i in itertools.product(*iterables)]

您必须将数字转换为字符串,然后合并结果:

print ''.join(map(str, t))
如果将输入字符串设置为以下开头,则可以避免转换:

iterables = [['1', '2', '3', '4'], ['88', '99'], ['a', 'b']]
for t in itertools.product(*iterables):
    print ''.join(t)
如果您只想将这些值一起打印(并且不以其他方式对它们执行任何操作),则使用
print()
作为函数(通过使用
from\uuuuuuu future\uuuuuuu import print\u函数
Python 2功能开关或使用Python 3):


为什么地图中有
列表
?只需执行
map(str,i)
@rassar:在Python2中,是的,在Python3中不是这样(因为
str.join()
使用列表输入工作得更快)。您的输出看起来不像列表。想必您的意思是,输出不应该看起来像元组,而是简单地连接起来?
from __future__ import print_function

iterables = [[1, 2, 3, 4], [88, 99], ['a', 'b']]
for t in itertools.product(*iterables):
    print(*t)