Simplicity is Python’s way to solve a problem.
Whenever I’d find myself in a situation where I was required to perform a reverse operation, more often than not, I would use a for loop or resort to find some function like reverse() that…
Partial is a higher order function which allows the partial application of a function. Suppose there is a function with lots of arguments but you need to change only one or two argument every time you use that function, Partial function comes to the rescue. Using Partial function, you can…
In Python, functions are first class citizens. But what does this mean?
The first class objects are program entity which have these five characteristics:
1. Can be created at runtime.
2. Can be assigned to a variable.
3. Can be passed as a argument to a function.
4. Can be…
As a programmer we all know what sorting is, so I will not write theory here and will go directly into code.
Python has inbuilt function sorted which can be use to sort any iterable. sorted function return the new sorted iterable unlike list.sort function which perform inplace sorting.
Each operator can be used in different way for different types of operands. for example when
+ is used with integers, it add integers to give result and when
+ is used with string, it concatenates the provided strings.
x, y = 10, 20
print(x + y) # 30a,b…
A Priority Queue is a type of queue in which every element is associated with priority and it returns the element of highest priority on every pop operation.
if priority is same the elements are return on basis of their insertion order.
We can easily implement priority queue in Python…
Make your code more functional.
Object oriented programming makes code understandable by encapsulating moving parts. Functional programming makes code understandable by minimizing moving parts. — Michael Feathers
map, filter and reduce are essentially just some of the most well-known, easy to use, higher-order functions that run provided callback on each…
return 'Hello World!';
console.log(sayHello()); // logs: Hello World!let…
Improve your code using higher order functions.
Higher order functions may sound some complicated technical term but it is nothing but a normal function which take function as arguments or return a function as their result. …
Step by step guide to understand closures.
Many developers find closures intimidating who come from language which does not support them. But there is nothing to be afraid from closures and the effort you put to understand closures will pay you many times over.
To understand the closures you need…