如何在Python中连接按元素排列的两个列表? [英] How to concatenate element-wise two lists in Python?

查看:84
本文介绍了如何在Python中连接按元素排列的两个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表,我想逐个元素地将它们连接起来.列表之一在连接之前要经过字符串格式化.

I have two lists and I want to concatenate them element-wise. One of the list is subjected to string-formatting before concatenation.

例如:

a = [0, 1, 5, 6, 10, 11] 
b = ['asp1', 'asp1', 'asp1', 'asp1', 'asp2', 'asp2']

在这种情况下,a经受字符串格式化.也就是说,新的aaa应该是:

In this case, a is subjected to string-formatting. That is, new a or aa should be :

aa = [00, 01, 05, 06, 10, 11]

最终输出应为:

c = ['asp100', 'asp101', 'asp105', 'asp106', 'asp210', 'asp211']

有人可以告诉我该怎么做吗?

Can somebody please tell me how to do that?

推荐答案

使用> strong> zip :

>>> ["{}{:02}".format(b_, a_) for a_, b_ in zip(a, b)]
['asp100', 'asp101', 'asp105', 'asp106', 'asp210', 'asp211']

这篇关于如何在Python中连接按元素排列的两个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆