Skip to main content

37.Python Filter,Map,Reduce

Python Filter:
    The python filter() function takes a list as a arguments and filter out the elements in the list based on a function condition and returns the filtered list.Filter takes 2 arguments:function and a sequence and remember to mention the format.

syntax:
list(filter(function ,sequence))#you can use tuple,set instead of list
Program
numbers=[5,7,28,25,40,400,56,78,94,70,100]
multiples=list(filter(lambda a:a%5==0,numbers))
print(multiples)
Output
[5, 25, 40, 400, 70, 100]
Python Map:
    The python map() can used to update the values in the list.While filters() remove the unwanted element in the list,map() performs some operation to the elements in the list and return the list.Map takes 2 arguments:function and a sequence .
syntax:
list(map(function ,sequence))#you can use tuple,set instead of list
Program
numbers=[5,7,28,25,40,400,56,78,94,70,100]
multiples=list(map(lambda a:a+20,numbers))
print(multiples)
Output
[25, 27, 48, 45, 60, 420, 76, 98, 114, 90, 120]
Python Reduce:
    Reduce applies a function of two arguments  to the elements of an sequence, starting with an initial argument.In short,it is used to perform some operations to all the values.This reduce function belongs to builtin module functools. It takes 2 arguments:function and a sequence
syntax:
reduce(function ,sequence)
Program
from functools import reduce
numbers=[5,7,28,25,40,400,56,78,94,70,100]
multiples=reduce(lambda a,b:a*b ,numbers))
print(multiples)
Output
1126664448000000000
    Interested in Learning python??Do view the video below know more about python!!
Happy Learning!!

Comments

Post a Comment

Popular posts from this blog

Get Ethical Hacking Project #1

Thanks for your interest in our course This is a paid course, 150 rs for Indian people, 5$ for international people Instructions to get course: Indian people can get the course by paying using this UPI id   tamilhacks@ybl  (KARTHIKEYAN T) send 150 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)     The above mentioned method is most preferable. if you don't have a upi id app, install  phonepe  or  google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100 Rs for tax and other charges here )   After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that . the course is in zip format, so after downloading the file extra

Learn c++ in Tamil | Complete guide and tutorial | Beginner to Advance all concepts explained.

hi guys welcome , all the coding used in video are available here : /* hi guys welcome to learn c++ in tamil what is C++ how what software your own program schools,clg,institute.... start 1.interest 2.patience 3.fun 4.practise computer program - app - programming source code - hardware - fb running , executing machine language :  101010 assembly lang : mov h1; high lang : c , c++....java , js , python  eg :  a+b .....1001010  compiler :  human to machine              machine to human  rules :  a+b;  usage:  games, manufacturing , embedded , finance , graphics , etc...  Guide: 1.problem 2.solution - alternative 3.program  - C++ 4.compile  - turboc , ide , codeblocks , cmd 5.result   - library file - linker : #include<iostream.h>    input , output std::cout<<"welcome";   standard character out << " "; primary section : 1.statements   ;  end 2.functions   main() 3.syntax  , syntax error pra

Get Bug Bounty Course

Thanks for your interest in our course Limited Offer This is a paid course, Rs 10000 ,Rs 1000  for Indian people, 75$ 15$ for international people , 50$ 10$ for Srilankan people Instructions to get course: Indian people can get the course by paying using this UPI id  tamilhacks@ybl  send 1000 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)    The above mentioned method is most preferable. if you don't have a upi id app, install phonepe or google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100Rs for tax and other charges here ) After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that. As for international peopl