[英]How do you fuse string items from two lists into new elements of a new list?
I am working with a set of numbers as strings, and I need to put them together but NOT add/subtract them. 我正在使用一组数字作为字符串,我需要将它们放在一起,但不能加/减它们。 Essentially I am working with this:
本质上,我正在与此:
a = ['12', '34', '56', '78']
b = ['78', '56', '34', '12']
And I need: 我需要:
c = ['1278', '3456', 5634', '7812']
Considering the above case you mentioned, you can simply do this as follows(assuming both the input arrays are of same length): 考虑到您提到的上述情况,您可以按照以下步骤简单地进行此操作(假设两个输入数组的长度相同):
for (int i=0; i<a.length; i++)
{
c[i]=(a[i]*100)+b[i];
}
Note: This is only for the example case you mentioned. 注意:这仅适用于您提到的示例案例。
压缩两个列表,然后将每个元素中的两个字符串连接起来:
c = [x + y for x, y in zip(a, b)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.