# python 不等长列表计算

0

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]

mls1212 | 初学一级 | 园豆：34

0

cap_list = list(map(lambda x, y: format(x + y, '.6f'),list, [0] + list1))

mls1212 | 初学一级 |园豆：34 | 2023-02-08 15:32

0

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];
}
}
``````

@〆灬丶: 我只会C# 不会Python

@中华鲟3670:

0

length = min(len(list), len(list1))
for i in range(1, length)：
list[i] + list1[i-1]

Sunny-King | 园豆：359 (菜鸟二级) | 2023-01-12 10:44
0

list(map(sum, zip(a,b)))

0

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)

您需要登录以后才能回答，未注册用户请先注册