list = [-7.642112, -23.15796, -23.64016, -23.78182, -23.69266, -23.74434, -23.67187]
list1 = [0.231624, 0.713826, 0.855483, 0.766328, 0.817999, 0.745523]
列表不一样长,我想list第二个元素开始和list1的元素一一对应相加,怎么实现?
cap_list = list(map(lambda x, y: format(x + y, '.6f'),list, [0] + list1))
c# 版:
double[] list = { -7.642112, -23.15796, -23.64016, -23.78182, -23.69266, -23.74434, -23.67187 };
double[] list1 = { 0.231624, 0.713826, 0.855483, 0.766328, 0.817999, 0.745523 };
double[] result = new double[list1.Length];
if (list.Length - list1.Length == 1)
{
for (int i = 0; i < list1.Length ; i++)
{
result[i] = list1[i] + list[i + 1];
}
}
我很好奇,你这答案 ta 用不用;希望其他答题者不要写 Python 版
@〆灬丶: 我只会C# 不会Python
@中华鲟3670:
我的意思是,这种索引、循环的问题都不用答;有个其他语言的答案自己还不会翻译,那怪谁
简单示例,可以自己完善
length = min(len(list), len(list1))
for i in range(1, length):
list[i] + list1[i-1]
list(map(sum, zip(a,b)))
list1 = [-7.642112, -23.15796, -23.64016, -23.78182, -23.69266, -23.74434, -23.67187]
list2 = [0.231624, 0.713826, 0.855483, 0.766328, 0.817999, 0.745523]
list3 = []
if len(list1) - len(list2) == 1:
for i in range(1,len(list1)):
list3.append(list1[i]+list2[i-1])
print(list3)