python列表内数相加_python如何把列表里面的部分值相加??

展开全部

程序代码如下:62616964757a686964616fe78988e69d8331333337623530# -*- coding: cp936 -*-

mobile = [

['apple', 'android', 'web', 1, 11],

['apple', 'android', 'web', 2, 22],

['apple', 'ios', 'web', 3, 33],

['apple', 'ios', 'web', 4, 44]]

out=[]

temp=""

index=-1

for ii in range(len(mobile)):

tempM=mobile[ii]

if temp != tempM[1]:

out.append(tempM)

temp = tempM[1]

index=index+1

else:

out[index][3]=out[index][3]+tempM[3]

out[index][4]=out[index][4]+tempM[4]

print out

tempout=[]

tempout.append(out[0][0])

tempout.append('total')

tempout.append(out[0][2])

tempout.append(out[0][3])

tempout.append(out[0][4])

for iii in range(1,len(out)):

tempout[3]=tempout[3]+out[iii][3]

tempout[4]=tempout[4]+out[iii][4]

tempout[3]=str(tempout[3])

tempout[4]=str(tempout[4])

out.append(tempout)

print out

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值