Skip to main content

Lambda, Map ,filter in python

Lambda:-

lambda is used to define an anonymous function which is used only once.
it takes an argument and expression it can have any number of arguments but only one expression
Syntex:
lambda a,b:a+b

Map:- 

Map takes two parameters and it is used to update values 

map(function or none, iterable)

filter:

 filter takes two parameters 

map(function or none, iterable)

when the function given is true  it stores the value in variable


ex:-

numbs=[1,2,3,4,5,6,7,8]

y=list(filter(lambda a: a%2==0,numbs))
x=list(map(lambda a:a*a,y))
print(x)

Comments

Popular posts from this blog

Magic constant generator -python3/hacker rank solution / tcs fresco play

  def   generator_Magic ( n1 ):      # the value starts from 3 and m is formula for constant,      #for generator  yield should use      for   a   in   range ( 3 , n1 + 1 ):          m = a * ( a ** 2 + 1 ) / 2          yield   m               # Write your code here if   __name__  ==  '__main__' :

Handling Exceptions 4 | Library| hacker rank solution

#!/bin/python3 import   math import   os import   random import   re import   sys # # Complete the 'Library' function below. #   def   Library ( memberfee , installment , book ):      if   installment > 3 :          raise   ValueError ( "Maximum Permitted Number of Installments is 3" )      #amount=memberfee/installment      elif   installment == 0 :          raise   ZeroDivisionError ( "Number of Installments cannot be Zero." )      else :          amount = memberfee / installment          print ( "Amount per Installment is  " + str ( amount ))      available = [ "philos...

Handling Exceptions 1 | hacker rank solution

  #!/bin/python3 import   math import   os import   random import   re import   sys # # Complete the 'Handle_Exc1' function below. # # def   Handle_Exc1 ():      a = int ( input ())      b = int ( input ())      if   a > 150   or   b < 100 :          raise   ValueError   ( "Input integers value out of range." )        if   a + b > 400 :          raise   ValueError ( "Their sum is out of range" )      print ( "All in range" )      # Write your code here if   __name__  ==  '__main__' :      try :          Handle_Exc1 ()   ...