I have been coding in Java for over 10 years now. And I often admire the completeness of Java core packaging.

Recently I started working more on Python and found it great for building ETL tasks, standalone script jobs, automation clients etc. I know we can do a lot more than that, but those are my current use cases.

One of the requirement I recently had was, given an array of objects sort them using a custom comparison logic.

The few options I thought about were:

‘sorted(given_arr, key=compare_function)’


But I quickly realized that the above methods are equivalent to Comparable<T>.compareTo(T> in Java

And the solutions is functools.cmp_to_key function. Here is an example for solving leetcode #179 problem



I am relatively new to python and more of a Java developer. But I love python for its simplicity.

AFAIK Python has min heap out of the box, but max heap methods are available but hidden. Please refer Python docs here .

In this article I wanted to document my learning about how to use heapq for max heap operation and the extract step needed. Also a sample code comparison with Java PriorityQueue

My implementation (not original) of Min Heap (just for understand purpose)