Seven Pythonic Functions You Should Know
Tags: python, programming, algorithms, tutorial
Published: 2022-02-01 00:39:47


Here is an article that tells you the seven functions that are way cool to help you with your time and energy. Fasten your seat belts to take a look at each one of them. The snippet codes are attached to give you essence of the articles that comes handy when you code it yourself with a cup of coffee.

## 1.Map

Map function is a common tool to start with and powerful tool to lessen your gigantic code into an aesthetic script that makes the code more readable and compact.
Instead of declaring a list and appending elements with an orthodox iterating practice, you can do it an instance with the help of map function.

![Map Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cnjcio3cbqbab2aef4xn.png)
The above program will print the prices of goods twice and that is how powerful map can be in one go.

## 2. Filter

It belong to pretty much the same room as map with a twist. The twist being that you can give a condition to pick the elements from the data structures (list/dictionary/set) that are your need unlike every other.
Remember that filter object, also map, is an iterable that can be accessed once you convert into a data structure of your choice. As suggested, the below snippet tells that filter object is an iterable.

![Filter Funtion](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wruburt967g2xp5f1g5z.png)

## 3. Zip

Generally used to pack elements present at the same index in two or more tuples into one unique tuple within the parent tuple is what zip function is good at.
Confusing? Don’t be. The code is pretty easy to understand the working but it will be much more helpful if you practice it once on your own.

![Zip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/06a59vx9n6sgo7j910h8.png)

## 4. Getsizeof

Getsizeof (lowercase) comes very handy on determining the size of the object. It is part of the system library and can be called to use.
On a lighter note, it is not some fancy function but the basic and important tool that is frequently used. Finding it interesting? Check how it behaves with generators to learn in depth.


![Getsizeof](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwlcp3zmelonvu91muac.png)

## 5. Dir

Dir function helps in detailing all the methods and attributes present in the object. It is useful in checking what better can we do with the objects or instances.
In the below snippet, magic methods or dunder methods, starting and ending with double underscore are printed on the screen when user calls the dir function.

![Dir Function](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/flb8gqe2k4169ew1ajkh.png)

## 6. Docstrings
It is somewhat near to comment but more structured and purpose filled as docstrings can be written while writing the code and can be accessed by __doc__ magic method.
The text appears in the output that is added by the developer while writing the code. Docstrings are very helpful in coding.

![Docstring](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsfdzrydhzbbw0a3cdzx.png)

## 7. datetime
Wonder how can you bring dynamic stuff like date and time into your code. It does not get any easier as in Python. Only practice one needs to do is to import the data and time module and if in need, the the option is add a separate class is always on the shelf.
It is viably visible how you can import tons of different module to carry out myriad number of tasks in Python. What comes attached with module is different functions for you served on the platter.

![datetime](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l5jj0myjhi1dlc20mvww.png)

In a similar fashion, you can access browse, send emails, create designs and what not. The adaptability and compatibility is what makes gives Python the spotlight in comparison to other languages. Why don’t you share with us your pythonic experiences in the comments below.