我有两个列表,我想按元素将它们连接起来。列表之一在连接之前要经过字符串格式化。
例如 :
a = [0, 1, 5, 6, 10, 11]
b = ['asp1', 'asp1', 'asp1', 'asp1', 'asp2', 'asp2']
在这种情况下,a
要进行字符串格式化。也就是说,newa
或aa
应为:
aa = [00, 01, 05, 06, 10, 11]
最终输出应为:
c = ['asp100', 'asp101', 'asp105', 'asp106', 'asp210', 'asp211']
有人可以告诉我该怎么做吗?
用途zip
:
>>> ["{}{:02}".format(b_, a_) for a_, b_ in zip(a, b)]
['asp100', 'asp101', 'asp105', 'asp106', 'asp210', 'asp211']
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句