Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to use map,filter concepts in python?

Description

To implement the concept of map, filter in python3.

Process
Map()

  map() is a function which takes twoarguments.

   Applies a function to all the items inan input_list.

   It used to number of coding lines inthe program.

Filter()

   Filter function is used to filter outall the elements of a sequence.

   The filter resembles a for loop but itis a built-in function and faster.

Sample Code

#map function
num_list = [1, 2, 3, 4, 5]
square = list(map(lambda x: x**2, num_list))
print(“Square of the list is:\n”)
print(square)
print(“\n”)

#filter function
num_range = range(-6, 6)
positive_values = list(filter(lambda x: x > 0, num_range))
print(“Positive number in the given range is:\n”)
print(positive_values)

Screenshots
How to use map,filter concepts in python