A Quick Implementation Guide

Image for post
Image for post
Pic from Unsplash.com

Recently I received an email from one of my readers asking me to write about Python’s complex topics such as Iterators, Generators, and Decorators. In this post, I’m going to cover the basics, implementation, and how to use them in your code.


An iterator is an object that can be iterated upon which means that you can traverse through all the values. List, tuples, dictionaries, and sets are all iterable objects.

To create an object as an iterator you have to implement the methods __iter__() and __next__() to your object where —

__iter__() returns the iterator object itself. …

Use these hacks and techniques…

Image for post
Image for post
Pic from Unsplash.com

While I have covered important (advanced) constructs of Python in the posts listed below, in this article I’m going to cover the basics with examples, that you should know.

Let’s dive in —

1. Map

In Python, map() function applies the given function to each item of a given iterable construct (i.e lists, tuples etc) and returns a map object.

Syntax —

map(function, iterable)

Implementation 1 —

numbers = (10, 20, 30)
result = map(lambda x: x+x, numbers)
total = list(result)

Output —

[20, 40, 60]

Implementation 2 —

list_one = ['monday', 'tuesday'] 

t = list(map(list, list_one))

Output —

[['m', 'o', 'n', 'd', 'a', 'y'], ['t', 'u', 'e', 's', 'd', 'a', 'y']]

2. Classes

Class is a blueprint or template to create objects. …

Use these hacks and techniques…

Image for post
Image for post
Pic from Unsplash.com

This is the part 3 of Advanced Python Made Easy. You can refer to the first two parts here —

Let’s dive in !

1. Defaultdict

Well, defaultdict belongs to collections module and is a high performance container data type which is used to overcome the issues of KeyError in python. It is a subclass of dict and returns a dict type object. It adds one writable instance variable and one method.

Syntax : defaultdict(default_factory)

where default_factory is the function which returns the default value of the dictionary.

Implementation —

from collections import defaultdict 

default_dict_var = defaultdict(list)

for i in range(10):
default_dict_var[i].append(i) …

Use these hacks and techniques…

Image for post
Image for post
Pic credits : Unsplash.com (Markus Spiske)

This is the part 2 of the series. You can read the part 1 below :

In this part we will see some advanced python constructs that will help you write efficient code, improve code readability and performance.

Let’s dive in!

1. Lambda Expression

Lambda is used to create small anonymous functions using “lambda” keyword and can be used wherever function objects are needed.It can any number of arguments but only one expression.

Syntax :

lambda argument(s): expression

Implementation —

#lambda arguments : expression
#A lambda function that adds 10 to the number passed in as an argument, and print the result
x = lambda a, b, c : a * b + c
print(x(5, 6…

Basics, hacks and techniques…

Image for post
Image for post
Pic from Unsplash.com

I’m creating this post not just to let the world (alright, atleast my readers! …

Use these hacks and techniques…

Image for post
Image for post
Pic from Unsplash.com

Python, created by Guido van Rossum in 1991, is an interpreted, high level-general purpose programming language. Most of us, working in software engineering field must have used Python in our work life. In this post, I’m going to cover the advanced python constructs and how you can efficiently use them to improve your code readability and performance. This is the part 1 and to be followed by Part 2 (coming soon).

1. Comprehensions

You must have heard about list comprehensions (Python 2.0). Comprehensions in Python are the constructs that allows sequence built from other sequences and while the list comprehensions are quite popular/frequently used, Python 3.0 …

Use these techniques …

Image for post
Image for post
Pic from Unsplash.com

Before you start implementing these techniques, load the data of your choice in your working environment. For this post, I’m using Iris data.

Start with importing the necessary libraries such as Pandas and Numpy and loading your data set. Once done, dive in the techniques below —

1. Split data using pandas

In the code below, we are splitting the data into a random sample of rows and removing them from the original data after dropping index values.

iris_data_new= df.copy()

Output —

(112, 5)

2. Binning Data

Binning is a technique to group/bin your data into multiple buckets which is very helpful if you dealing with continuous numeric data. In pandas you can bin the data using functions cut and cut. …

Here is what they found…

Image for post
Image for post
Pic credits : Reddit

For almost a decade, Stack Overflow’s annual Developer Survey has been the largest survey of people who code around the world. This year they did a survey on 60,000+ software developers and shared some of the amazing statistics.

In this article, I’m going to write a detailed analysis of their survey result. So get ready to read some amazing analysis —

How different technologies are correlated with each other and how developers use these technologies?

This network graph shows which technologies are most highly correlated with each other. The size of each circle corresponds to the proportion of survey respondents who use the technology tool.

Ruby and Rails tend to get used together. Similarly .NET developers look forward to developing on Windows machines and Azure Cloud. …

“After all, what’s more human than the fight for survival?” — Tokyo

Image for post
Image for post
Gif (Source and credits: Giphy)

I just finished watching the 4th season of Money Heist, a popular Spanish Netflix series and I think it’s one of the best TV series I’ve seen in recent years.

The story focuses on a group of robbers who planned a heist at the Royal Mint of Spain.

Characters —

Headed by a man called “The Professor”.

His band of thieves — named after a city.

Image for post
Image for post
Money Heist Character names (Image source and credits: Pinterest)

The story is very compelling and its dialogues are impressive. …


Naina Chaturvedi

🇺🇸,World Traveler,Women in Tech,Sr. SDE-Earning my bread using 0&1,Coursera Instructor ML & GCP, Trekker, Avid Reader,I write for fun@AI & Python publications

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store