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 by passing a function that returns a comparable value for each element in the list. With the optional Boolean reverse argument, you can switch from ascending (reverse=False) to descending order (reverse=True).

Here’s a short overview example that shows you how to use the arguments

Continue reading the original article

The Real Python Podcast – Episode #1: Python Decorators and Writing for Real Python

In this first episode, Christopher interviews Geir Arne Hjelle from the Real Python Team.

You’ll learn about Geir Arne’s background as a Pythonista and PyCon speaker, the tutorials he’s written for the site, how Python decorators can help you write better code, and what Real Python’s tutorial publishing process looks like behind the scenes.

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Continue reading the original article

PyDev of the Week – Abigail Mesrenyame Dogbe

This week we welcome Abigail Mesrenyame Dogbe (@MesrenyameDogbe) as our PyDev of the Week! Abigail is active with the PyLadies organization in Africa and has also helped organize PyCon Africa. Abigail is also a fellow of the Python Software Foundation.

Let’s spend some time getting to know Abigail better!
Can you tell us a little about yourself (hobbies, education, etc):
I worked with the Internal Audit Department at the Ghana Community Network Services Limited (GCNet) after obtaining a BSc in Computer Science and Engineering from the University of Mines and Technology in Tarkwa, Ghana. Growing up, I struggled with Mathematics and did lots

Continue reading the original article

The Real Python Podcast – Episode #2: Learn Python Skills While Creating Games

In this episode, Christopher interviews Jon Fincher from the Real Python Team. Jon talks about his recent articles on PyGame and Arcade. They discuss if game programming is a good way to develop your Python programming skills, and if a game would make a good portfolio piece. He compares the two popular Python game libraries of Arcade and PyGame, and discusses about how to find assets for your own creations.

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to

Continue reading the original article

How to Use any() in Python

As a Python programmer, you’ll frequently deal with Booleans and conditional statements—sometimes very complex ones. In those situations, you may need to rely on tools that can simplify logic and consolidate information. Fortunately, any() in Python is such a tool. It looks through the elements in an iterable and returns a single value indicating whether any element is true in a Boolean context, or truthy.
In this tutorial, you’ll learn:

How to use any()
How to decide between any() and or

Let’s dive right in!

Python Pit Stop: This tutorial is a quick and practical way to find the info you need, so you’ll be

Continue reading the original article

Autoencoders for Content-based Image Retrieval with Keras and TensorFlow

In this tutorial, you will learn how to use convolutional autoencoders to create a Content-based Image Retrieval system (i.e., image search engine) using Keras and TensorFlow.
A few weeks ago, I authored a series of tutorials on autoencoders:

Part 1: Intro to autoencoders
Part 2: Denoising autoencoders
Part 3: Anomaly detection with autoencoders

The tutorials were a big hit; however, one topic I did not touch on was Content-based Image Retrieval (CBIR), which is really just a fancy academic word for image search engines.
Image search engines are similar to text search engines, only instead of presenting the search engine with a text query, you instead

Continue reading the original article

Python: How to Count Elements in a List Matching a Condition?

I stumbled across this question when browsing through StackOverflow and it got me thinking: what’s the best way to count the number of elements in a list that match a certain condition? Can you generalize this way to both general conditions (e.g. x>3) and regular expressions (e.g. ‘a.*’)?

Short answer: you can count the number of elements x that match a certain condition(x) by using the one-liner expression sum(condition(x) for x in lst). This creates a generator expression that returns True for each element that satisfies the condition and False otherwise. Since the True and False values are represented by

Continue reading the original article