samedi 31 janvier 2015

checking multiple if statements

let's say I wanted to organize a list of numbers by positive, negative, and floats. how would I get this code to add a number to multiple lists such as pos and flt? For example 5.6. instead of just adding it to pos and moving on to the next one with out checking if 5.6 is a float as well?


Thanks



list_num=[1,-1,-3,5.6,9.0]
neg=[]
pos=[]
flt=[]
for n in list_num:
if n<0:
neg.append(n)
if n>=0:
pos.append(n)
if str(n).isdigit()==False and n>0:
flt.append(n)
print neg
print pos
print flt

Aucun commentaire:

Enregistrer un commentaire