sort float python list -


here code:

for line in lines:    name,price,yield = line.split(',')    part in [price,yield]:        part = float(part)        company = company(name,price,yield)  templist = sorted(companylist, key=lambda company: company.price) company in templist:     print(company.price) 

the printed list ranks 49.0 smaller number 5.0 know going wrong?

this:

for part in [price,yield]:     part = float(part)     company = company(name,price,yield) 

does not think does. numerical values of price , yield not assigned respective original names, literally name part (so overwritten in second iteration).

the line create company misindented, should outside for loop.

the simplest way fix replace 3 lines quoted following single line:

company = company(name, float(price), float(yield)) 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -