100 Code Puzzles to Train Your Rapid Python Understanding

Some coders possess laser-like code understanding skills. They look at a piece of source code, and the meaning pops immediately into their great minds. If you present them with a new code snippet, they’ll tell you in a few seconds what it does. Since I’ve started to train this skill of rapid code understanding in … Read more

The Ultimate Guide to Python Lists

The most important collection data type in Python is the list data type. You’ll use lists basically in all your future projects. So take your time and invest a good hour or so to study this guide carefully. Overview — Creating a List in Python There are many ways of creating a list in Python. … Read more

Python List Sort Key

Every computer scientist loves sorting things. In this article, I’ll show you how you can modify the default Python sorting behavior with the key argument. Definition and Usage: To customize the default sorting behavior of the list.sort() and sorted() method, use the optional key argument by passing a function that returns a comparable value for … Read more

Python – How to Sort a List of Dictionaries?

In this article, you’ll learn the ins and outs of the sorting function in Python. In particular, you’re going to learn how to sort a list of dictionaries in all possible variations. [1] So let’s get started! How to Sort a List of Dictionaries … … By Value? Problem: Given a list of dictionaries. Each … Read more

How to Read All Lines of a File in a Python One-Liner?

Say your file is stored in file ‘code.py’. Now, you can open the file, read all lines, get rid of leading and trailing whitespace characters, and store the result in a Python list in a single line of code. Here’s the code: Python is beautiful! ? Try it Yourself: Where to Go From Here? If … Read more

How to Sort a List Alphabetically in Python?

Problem: Given a list of strings. Sort the list of strings in alphabetical order. Example: Solution: Use the list.sort() method without argument to solve the list in lexicographical order which is a generalization of alphabetical order (also applies to the second, third, … characters). Try It Yourself: Related articles: The Ultimate Guide to Python Lists … Read more

Python List sort() – The Ultimate Guide

Every computer scientist loves sorting things. In this article, I’ll show you how Python does it—and how you can tap into the powerful sorting features of Python lists. Definition and Usage: The list.sort() method sorts the list elements in place in an ascending manner. To customize the default sorting behavior, use the optional key argument … Read more