MLWhiz | AI Unwrapped

MLWhiz | AI Unwrapped

Share this post

MLWhiz | AI Unwrapped
MLWhiz | AI Unwrapped
Python Pro Tip: Start using Python defaultdict and Counter in place of dictionary
Copy link
Facebook
Email
Notes
More

Python Pro Tip: Start using Python defaultdict and Counter in place of dictionary

Rahul Agarwal's avatar
Rahul Agarwal
Apr 22, 2019
∙ Paid

Share this post

MLWhiz | AI Unwrapped
MLWhiz | AI Unwrapped
Python Pro Tip: Start using Python defaultdict and Counter in place of dictionary
Copy link
Facebook
Email
Notes
More
Share
Python Pro Tip: Start using Python defaultdict and Counter in place of dictionary

Learning a language is easy. Whenever I start with a new language, I focus on a few things in below order, and it is a breeze to get started with writing code in any language.

  • Operators and Data Types: +,-,int,float,str

  • Conditional statements: if,else,case,switch

  • Loops: For, while

  • Data structures: List, Array, Dict, Hashmaps

  • Define Function

However, learning to write a language and writing a language in an optimized way are two different things.

Every Language has some ingredients which make it unique.

Yet, a new programmer to any language will always do some forced overfitting. A Java programmer, new to python, for example, might write this code to add numbers in a list.

x=[1,2,3,4,5]

sum_x = 0
for i in range(len(x)):
    sum_x+=x[i]

While a python programmer will naturally do this:

sum_x = sum(x)

In this series of posts named ‘Python Shorts’, I will explain some simple constructs that Python provides, some essential tips and some use cases I come up with regularly in my Data Science work.

Thi…

Keep reading with a 7-day free trial

Subscribe to MLWhiz | AI Unwrapped to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Rahul Agarwal
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More