Tuesday, December 11, 2018

Python ninja Bootcamp 33-Reduce( )

Learn Python like a Professional! Take You from 0 to Hero






In this Python lecture, we will learn about the Reduce function.

"Reduce is a function that takes a function & a sequence as parameter, returns a single.This function is define under the functools module ".


Reduce( ) in Python

Let's see the example

from functools import reduce




Calculate the sum of all elements in the list 
l=[1,2,3,4]

reduce(lambda a,b:a+b,l)
>>10

Calculate the largest number in the list
reduce(lambda a,b:a if a>b else b,[15,68,23,70,49])
>>70


EDITS ARE WELCOMED!!

In the next Blog, we will discuss filter( )

https://sngurukuls247.blogspot.com/2018/12/python-ninja-bootcamp-34-filter-function.html

......................................................................................................................................

Follow the link below to access Free Python Lectures-
https://www.youtube.com/channel/UCENc9qI7_r8KMf6-_1R1xnw

Instagram-
https://www.instagram.com/python.india/

View the Jupyter Notebook for this lecture

Download the Jupyter Notebook for this lecture 



Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com

No comments:

Post a Comment