如何将2个字符串转换为键?

时间:2014-10-29 09:25:38

标签: python

我有两个带字母值的字符串(a-e)&数值(1-5):

 num = 12345
 let = abcde

如何使用for循环获取此内容?

[1a, 2b, 3c, 4d, 5e]

2 个答案:

答案 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)]