summing elements of a list of csv lists in python -
i have list of csv lists like:
[[0, 0], [0, 2], [1, 1], [2, 0], [0, 3], [1, 2], [2, 1], [3, 0]] what want sum each individual list i.e create new list composed of each comma seperated variable summed, , check if equal value i.e:
check [0+0,0+2,1+1,2+0..... equal number
i have gotten far as:
if sum(gcounter)==3: gamma=true print(gamma) else: pass i have tried sum(int..., , tried using loop amongst others keeps throwing same error each time try different method typeerror: unsupported operand type(s) +: 'int' , 'list' problem sum function
trying work out has frankly left me feeling listless appreciate help!!!
are looking like:
>>> lst = [[0, 0], [0, 2], [1, 1], [2, 0], [0, 3], [1, 2], [2, 1], [3, 0]] >>> print ([x x in lst if sum(x) == 3]) [[0, 3], [1, 2], [2, 1], [3, 0]] essentially loop on lst getting 1 sublist @ time. sum sublist , if equals 3, keep sublist in output list.
Comments
Post a Comment