python - return and print does not give same result -


what i'm trying take entered string separated commas , change list each list key print associated value.

def main():     mydict = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5....}     u_input = input("enter letter")     mylist = [x.strip() x in u_input.split(',')]     result = searchdict(mylist)     print(result)  def searchdict(key):     ml in key:         value = mydict.get(ml, "not found")         re = []         re.append(value)         print('-'.join(re)) #this 1 shows each value each entered key separated comma not print in 1 line prints 'none' on end      #res = '-'.join(re)     #return res //this shows value first key if enter multiple letter  main(); 

the prob that, if return 'res' instead of printing it, i'm getting first key value.

output print(if enter a, b): 1, 2, none

output return 1

are these lines indented properly?

for ml in key: value = mydict.get(ml, "not found");  re = []; re.append(value) 

i think want this:

re = [] ml in key:     value = mydict.get(ml, "not found")         re.append(value) return '-'.join(re) 

btw no semicolons used in python.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -