The problem with python's map and filter...

… and how we might fix it. This is NOT a hate post. Let me say that again, This is NOT a hate post! Python is a fine language and it was my first programming language. Like the initial stages of falling in love with someone, you can’t see the flaws, the same was with python :) But as time goes by and the initial limerance fades, you start seeing the flaws....

November 27, 2021 · 10 min · Abhinav Omprakash

Recursion is recursion is recursion is...

Defining recursion in terms of itself is an old joke among programmers. Despite the fact that it frustrates a lot of new-comers, we don’t change it. I like to define recursion as “Iteration for the cool kids”. I don’t mean this in a snobbish, let-us-exclude-the-for-loopers kinda way, but rather in a tone of appreciation. Recursion is an elegant way of doing things. Recursive alogrithms are concise, have less noise and have immutability baked in (always a plus)....

October 27, 2021 · 9 min · Abhinav Omprakash

Classes are dictionaries draped in syntactic silk.

In this post, we are going to see how we can implement classes if python didn’t come with a class construct, read till the end if you’d want to know why I put you made you go through all this pain fun😉 What the heck is a Class? There are a lot of philosophical discussions about what classes are but I’m not concerned with that. In the simplest terms, a class is an entity that has data and functionality related to that data, these are called attributes and methods....

August 25, 2021 · 10 min · Abhinav Omprakash

Fold is gold: understanding reduce

Introduction reduce or foldleft is a very powerful function, but it can be quite tricky to understand and use. In fact, I used to think that reduce was an obscure function, that reduced (hehe) the readability of a program. If you ever want to make it as a functional programmer, understanding reduce is as important as important as knowing how to reverse linked list. I’m joking, knowing how to reverse a linked list is not that important, and it can be done with reduce!...

July 11, 2021 · 10 min · Abhinav Omprakash

Understanding partial functions

Welcome to the land of contrived examples and imperfect metaphors. Today we will be visiting a store called the five-item store. You’re only allowed to buy five items, no more, no less. The moment we enter the store, a cashier sees us and begins tailing us, and he keeps repeating “give me your items for so that I can make a bill” over and over again, so we just pick up an item and give it to him, and he shrieks and says “give me all five at the same time or none at all....

June 7, 2021 · 8 min · Abhinav Omprakash

How to use timeit and pretty timeit

Here’s the situation, you have two algorithms in front of you, and you want to see which one is faster. Suppose we wanted to see what’s faster for constructing a list: a for loop, or a list comprehension. A simple solution might look like this. import time def number_list_1(count_up_to): lst=[] for i in range(count_up_to): lst.append(i) def number_list_2(count_up_to): lst=[i for i in range(count_up_to)] if __name__=="__main__": import time start = time.time() number_list_1(10000) end =time....

May 7, 2021 · 4 min · Abhinav Omprakash