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

Matplotlib Boxplot – A Helpful Illustrated Guide

Do you want to plot numerical data? And do it in a beautiful, engaging, and scientifically sound way? And do all of this in a few simple lines of code? You’re in the right place! A great way to plot numerical data is the matplotlib boxplot. It displays the median, the interquartile range, and outliers … Read more

Python List count()

This tutorial shows you everything you need to know to help you master the essential count() method of the most fundamental container data type in the Python programming language. Definition and Usage: The list.count(x) method counts the number of occurrences of the element x in the list. Here’s a short example: In the first line … Read more

Coding Doctor Against COVID-19

COVID-19 is everywhere. In this article, I want to express my deep gratitude for the doctors, nurses, and medical personnel working 70-hours or more per week to mitigate the adverse effects of the virus. Here’s a pic of Finxter user Albrecht, a “retired” medical doctor supporting a COVID-19 test station in Germany: I asked the … Read more

Python List reverse()

This tutorial shows you everything you need to know to help you master the essential reverse() method of the most fundamental container data type in the Python programming language. Definition and Usage: The list.reverse() reverses the order of the elements in the list. If you want to create a new list with reversed elements, use … Read more