Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中组合元素_Python_List_Elements - Fatal编程技术网

在Python中组合元素

在Python中组合元素,python,list,elements,Python,List,Elements,我对Python非常陌生,所以也许我偶然发现了答案,但我没有意识到,但我已经搜索和试验了一整天的代码,我仍然对以下问题感到困惑: 鉴于以下两个列表: List1 = [1, 2, 3] List2 = ['a', 'b', 'c'] 您将如何创建列表3 List3 = ['1a', '2b', '3c'] 你听说了吗 例如: >>> List1 = [1, 2, 3] >>> List2 = ['a', 'b', 'c'] >>> [st

我对Python非常陌生,所以也许我偶然发现了答案,但我没有意识到,但我已经搜索和试验了一整天的代码,我仍然对以下问题感到困惑:

鉴于以下两个列表:

List1 = [1, 2, 3]
List2 = ['a', 'b', 'c']
您将如何创建列表3

List3 = ['1a', '2b', '3c']
你听说了吗

例如:

>>> List1 = [1, 2, 3]
>>> List2 = ['a', 'b', 'c']
>>> [str(i)+j for i,j in zip(List1,List2)]
['1a', '2b', '3c']

这是一个很好的用例:

>>> List1 = [1, 2, 3]
>>> List2 = ['a', 'b', 'c']
>>> [str(i)+j for i,j in zip(List1,List2)]
['1a', '2b', '3c']
>>> l1 = [1, 2, 3]
>>> l2 = ['a', 'b', 'c']
>>> 
>>> ['%d%s' % item for item in zip(l1, l2)]
['1a', '2b', '3c']
['{}{}'.format(a,b) for a,b in zip(list1, list2)]