0
result = map(lambda x: dictionary[x], mylist)

I am learning lambda expressions and the concept seems to be little confusing. I am trying to understand what this lambda function is supposed to do and rewrite as a separate function. My understanding is that it takes an item from the list and it then get a value from the dictionary...

Below is how I attempted to rewrite the lambda part

  result = list()
  for x in mylist:
      value = dictionary[x]
  result.append(value)
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425

1 Answers1

1

Read this Why are Python lambdas useful?

dictionary = {'a':5,'b':6,'c':7}
mylist = ['a','c']

def f1(x):
    return dictionary[x]

#lambda x: dictionary[x]

result= map(f1, mylist)
print(list(result))
Pritish kumar
  • 514
  • 6
  • 13