python - If-statement confusion -


i have function 1 below. try let have checklist('sky high'), output produce 30,19 not 0,30,0,19 current code right now. , if have checklist('blue sky'), output produce 0. how can alter code?

def checklist(argument):      data = [["sky",'79'],             ["sky high",'30'],             ["sky sky",'50'],             ["sky high",'19']]      row in data:         if argument == row[0]:            print row[1]          else:            print 0 

def checklist(argument):     data = [["sky",'79'],             ["sky high",'30'],             ["sky sky",'50'],             ["sky high",'19']]     #create list first     ans = [x[1] x in data if x[0]==argument]     #if list has 0 items return 0 else return str.join() version of list     return ", ".join(ans) if ans else 0  print checklist('sky high') print checklist('blue sky') 

output:

30, 19 0 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -