Dict to List — How to Convert a Dictionary to a List in Python

Summary: To convert a dictionary to a list of tuples, use the dict.items() method to obtain an iterable of (key, value) pairs and convert it to a list using the list(…) constructor: list(dict.items()). To modify each key value pair before storing it in the list, you can use the list comprehension statement [(k’, v’) for k, v in dict.items()] replacing k’ and v’ with your specific modifications.

In my code projects, I often find that choosing the right data structure is an important prerequisite to writing clean and effective code. In this article, you’ll learn the most Pythonic way to convert

Continue reading the original article

Python’s reduce(): From Functional to Pythonic Style

Python’s reduce() is a function that implements a mathematical technique called folding or reduction. reduce() is useful when you need to apply a function to an iterable and reduce it to a single cumulative value. Python’s reduce() is popular among developers with a functional programming background, but Python has more to offer.
In this tutorial, you’ll cover how reduce() works and how to use it effectively. You’ll also cover some alternative Python tools that can be more Pythonic, readable, and efficient than reduce().
In this tutorial, you’ll learn:

How Python’s reduce() works
What the more common reduction use cases are
How to solve these use

Continue reading the original article

OpenCV Selective Search for Object Detection

Today, you will learn how to use OpenCV Selective Search for object detection.

Today’s tutorial is Part 2 in our 4-part series on deep learning and object detection:

Part 1: Turning any deep learning image classifier into an object detector with Keras and TensorFlowPart 2: OpenCV Selective Search for Object Detection (today’s tutorial)Part 3: Region proposal for object detection with OpenCV, Keras, and TensorFlow (next week’s tutorial)Part 4: R-CNN object detection with Keras and TensorFlow (publishing in two weeks)

Selective Search, first introduced by Uijlings et al. in their 2012 paper, Selective Search for Object Recognition, is a critical piece of computer vision,

Continue reading the original article

PyDev of the Week: Florian Dahlitz

This week we welcome Florian Dahlitz (@DahlitzF) as our PyDev of the Week! Florian is a contributor to the CPython programming language and the PyTest framework. He is also a contributor to Real Python. You can check out Florian’s personal blog or get his newsletter to keep up-to-date with him.
Let’s spend some time getting to know Florian!
Can you tell us a little about yourself (hobbies, education, etc):
My name is Florian and I’m studying applied computer-science in Germany. I’m currently working on my bachelor thesis focusing on natural language processing. In my free time I code as much as possible, write

Continue reading the original article


This is the 2500th post on this blog. That’s a lot of writing. I estimate
this site has about 480,000 words in total, enough for five books.I’ve been writing here for more than 18 years. The pace is different than
when I started: last year I wrote 33
posts. Compare that to 2003, when I wrote more than ten times as many:
441 posts!
Twitter has siphoned off some of the
short-post energy, but also interests shift over time.Writing is a good way to understand things, and to learn things. People
mostly think of writing as a way to teach and explain, and I am glad when

Continue reading the original article

The Most Pythonic Way to Compare Two Lists in Python

Problem: Given are two lists l1 and l2. You want to perform either of the following:

1. Boolean Comparison: Compare the lists element-wise and return True if your comparison metric returns True for all pairs of elements, and otherwise False.2. Difference: Find the difference of elements in the first list but not in the second.

Example: You start with two lists.

l1 = [1, 2, 3, 4, 5]
l2 = [1, 2, 3]

# 1. Boolean Comparison
result = False

# 2. Difference
result = [4, 5]

Let’s discuss the most Pythonic ways of accomplishing these problems. We start with five ways to perform the Boolean comparison and look

Continue reading the original article

Python Freelancing | How to Exploit This Disruptive Mega Trend (as a Coder)

Short summary of the main points in the video:

Freelancing is a mega-trend that will disrupt the organization of the world’s labor in the next 10-20 years.Freelancing platforms such as Upwork and Fiverr grow at 20% per year.You can participate in this trend by focusing on one tiny niche—and become world-class at it.The earlier you start getting practical experience, the higher your competitive advantage will be!

You can get help building a thriving coding business with the Finxter resources to boost your freelancing power and earning potential:

Become Python Freelancer Course

Both links open a new Finxter website in a new tab.

Freelancer Webinar

This graphic

Continue reading the original article

The Most Pythonic Way to Remove Multiple Items From a List

Python’s built-in list data structure has many powerful methods any advanced Python programmer must be familiar with. However, some operations on lists can’t be performed simply by calling the right method.

You can add a single item to a list using the method append(item) on the list. If you want to add a list of items to another list, there is the method expand(items) which does the job for you.

The same holds if you want to delete an item from a list, you simply call the method remove(item)and you get the desired outcome.

But, did you ever wonder how to delete

Continue reading the original article