3 Smartest Python Functions🔥

Python has a lot of interesting functions which makes life easier by doing operations under the hood.:bulb:

Having such functions help us avoiding use of loops. Let’s have a look:

  1. Map⚡

The map() function takes in another function and an iterable like lists, tuples as arguments.

Then performs that operation in the function on the complete iterable. The returned object can then be passed into another iterable like lists.

  1. Filter⚡

The filter() function returns True when a certain condition is satisfied.

This condition can be applied on an iterable and its contents can be “filtered”. Again, better than having a loop.

  1. Reduce :zap:

The reduce() function is a bit different and will have to be imported from the functools module.

From the example in the image, what it does is,

1 gets added to 2, results in 3
This 3 gets added to next 3, results in 6
This 6 gets added to 4, results in 10

See what it did?:bulb:

This is just a very simple example to show its working. Reduce function is capable and used to do far more complex operations.

#python #datascience #machinelearning