合并两个列表的每个项目 separet.py
combinding each items for both list separet.py
我试图寻找答案,但找不到。
我有两个列表。两个列表都有 71 项。
我希望合并两个列表中的每个索引。
- These two list that I want to combine
- This is what I get but it is not what I want
- This is the result that I want
你可以这样做:
extensions =['.sp1', '.sp1', '.sp2']
my_numbers =[4, 16, 128]
new_list = []
for x in range(len(my_numbers)):
new_list.append("".join([str(my_numbers[x]), extensions[x]]))
print(new_list)
输出:
['4.sp1', '16.sp1', '128.sp2']
我试图寻找答案,但找不到。
我有两个列表。两个列表都有 71 项。
我希望合并两个列表中的每个索引。
- These two list that I want to combine
- This is what I get but it is not what I want
- This is the result that I want
你可以这样做:
extensions =['.sp1', '.sp1', '.sp2']
my_numbers =[4, 16, 128]
new_list = []
for x in range(len(my_numbers)):
new_list.append("".join([str(my_numbers[x]), extensions[x]]))
print(new_list)
输出:
['4.sp1', '16.sp1', '128.sp2']