题目:
a = [1,2,3,4,5] b = ["a","b","c","d","e"]
如何得出:
c = ['a1', 'b2', 'c3', 'd4', 'e5']
解题思路
1、a、b两个列表长度一致,获取长度
2、一个for循环,每次获取同下标值
3、字符串拼接,添加到c列表
答案:
- 方法一
- 根据索引值相同的特性得出
c = [] for i in a: for k in b: if a.index(i) == b.index(k): f = str(i) c.append(k+f) print(c)
- 方法二
- 根据相同长度的特性得出
c = [] for i in range(0,len(a)): a1 = a[i] b1 = b[i] c.append(f"{b1}{a1}") print(c)
标签:index,提取,合并,a1,b1,print,长度,数据,append From: https://www.cnblogs.com/LoLong/p/16799971.html