Python’s Counter: The Pythonic Way to Count Objects

Counting several repeated objects at once is a common problem in programming. Python offers a bunch of tools and techniques you can use to approach this problem. However, Python’s Counter from collections provides a clean, efficient, and Pythonic solution. This dictionary subclass provides efficient counting capabilities out of the box. Understanding Counter and how to use it efficiently is a convenient skill to have as a Python developer. In this tutorial, you’ll learn how to: Count several repeated objects at […]

Read more

Reverse Python Lists: Beyond .reverse() and reversed()

Sometimes you need to process Python lists starting from the last element down to the first—in other words, in reverse order. In general, there are two main challenges related to working with lists in reverse: To meet the first challenge, you can use either .reverse() or a loop that swaps items by index. For the second, you can use reversed() or a slicing operation. In the next sections, you’ll learn about different ways to accomplish both in your code. Reversing […]

Read more

Natural Language Processing With Python’s NLTK Package

Natural language processing (NLP) is a field that focuses on making natural human language usable by computer programs. NLTK, or Natural Language Toolkit, is a Python package that you can use for NLP. A lot of the data that you could be analyzing is unstructured data and contains human-readable text. Before you can analyze that data programmatically, you first need to preprocess it. In this tutorial, you’ll take your first look at the kinds of text preprocessing tasks you can […]

Read more

Python Basics: Paperback Now Available!

After years of writing, reviewing, and testing, we’re delighted to announce that Python Basics: A Practical Introduction to Python 3 is now available in paperback! It’s been rewarding to hear how readers have been using this book to supercharge their learning. After receiving so much community feedback, we’re confident that you’ll build a strong foundation for your Python journey with this book: You’ll not only cover the core concepts you really need to know, but you’ll also learn them in […]

Read more