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
  • 732,580
  • 175
  • 1,330
  • 1,459

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
  • 512
  • 6
  • 13