Append in Python clearing list -


i have piece of code:

bincounts = [] in range(len(bins)):     bincounts.append(0) 

where bins array looks this:

['chry', '28626328', '3064930174', '28718777', '92449', '49911'], ['chry', '28718777', '3065022623', '28797881', '79104', '49911'], ['chry', '28797881', '3065101727', '59373566', '30575685', '49912']] 

when run range(len(bins)) in python's interactive mode, get:

[0, 1, 2] 

but when test whole piece of code, i'm getting

[0,0,0] 

i believe should getting

[0, 1, 2, 0]  

this resulting in division 0 error later on down line. why happening? how can fix it? appreciate guidance!

you receiving list of zeros because of line:

bincounts.append(0) 

each time through loop, append 0 bincount


if goal put 0 @ end of list, pull line out of for loop

for in range(len(bins)):     # logic bincounts.append(0) 

it appears creating list values in range 0 through length of bins. can without for loop:

bincounts = range(len(bins)) bincounts.append(0) 

at end of these 2 lines, bincounts be:

[0, 1, 2, 0] 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -