猿问

如何在Python中合并两个列表

import string

l=list(string.ascii_lowercase)

u=list(string.ascii_uppercase)

    

我希望这些列表像这样合并


A=[('a','A'),('b','B'),('c','C')]

请告诉我该怎么做


慕尼黑5688855
浏览 102回答 1
1回答

繁星coding

只需使用zip:A = list(zip(l,u))输出:>>> A[('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D'), ('e', 'E'), ('f', 'F'), ('g', 'G'), ('h', 'H'), ('i', 'I'), ('j', 'J'), ('k', 'K'), ('l', 'L'), ('m', 'M'), ('n', 'N'), ('o', 'O'), ('p', 'P'), ('q', 'Q'), ('r', 'R'), ('s', 'S'), ('t', 'T'), ('u', 'U'), ('v', 'V'), ('w', 'W'), ('x', 'X'), ('y', 'Y'), ('z', 'Z')]
随时随地看视频慕课网APP

相关分类

Python
我要回答