我有两个带字母值的字符串(a-e)&数值(1-5):
num = 12345
let = abcde
如何使用for循环获取此内容?
[1a, 2b, 3c, 4d, 5e]
答案 0 :(得分:4)
假设let和num是字符串
>>> num = "12345"
>>> let = "abcde"
您可以使用zip:
>>> [''.join(i) for i in zip(num,let)]
['1a', '2b', '3c', '4d', '5e']
答案 1 :(得分:2)
num = '12345'
let = 'abcde'
keys = [n+l for n,l in zip(num, let)]