Python: using heapq module to find n largest itemsToday, I'm going to tell about using the heapq module. As you probably know, the easiest way to find the largest element in a collection in Python is by using the max() method. Or min() to find the smallest one. But what if you need to find n largest...Dec 25, 2020 · 12 min readpythonista.hashnode.dev
Python tips: playing with round()You have probably already worked with the Python built-in round() function. It takes a number as an argument and simply rounds it. But depending on its second parameter, the function can actually perform a range of rounding calculations with differen...Dec 23, 2020 · 3 min readpythonista.hashnode.dev
Python tips: use generators more!When writing a function that's supposed to return a sequence of results, returning some data structure like a list or dictionary is often the most obvious choice, yet not necessarily the most effective one. Sometimes, it can be beneficial to design y...Dec 17, 2020 · 8 min readpythonista.hashnode.dev
Python tips: how to 'reuse' a generator?Generators can help you write reusable and scalable Python code, but the problem is that complicated processing often requires using the same data multiple times. However, the issue with generators is that they exhaust themselves, meaning they can pr...Dec 16, 2020 · 12 min readpythonista.hashnode.dev
Python tips: unpack data gracefully with starred expressionsDo you know how to easily assign data to variables from lists of different sizes? How to get a 'head' and 'tail' from a tuple without using clumsy indexes? How to use star expressions? Or simplify your code with a throaway variable? If not, get comfy...2CVDec 11, 2020 · 8 min readpythonista.hashnode.dev