DEV Community

Cover image for 5 Python Built-ins You’re Not Using (But Should Be)
Neha Christina
Neha Christina

Posted on

5 Python Built-ins You’re Not Using (But Should Be)

You don’t need a library. You don’t need to pip install anything. These five tools are already sitting inside Python, waiting for you to use them.

Most junior developers don’t know they exist. Senior developers reach for them every single day.

Let’s fix that.


1. zip()

Loop over multiple lists at the same time.

How most beginners do it:

names = ['Alice', 'Bob', 'Carol']
scores = [95, 87, 92]

for i in range(len(names)):
    print(names[i], scores[i])
Enter fullscreen mode Exit fullscreen mode

How you should do it:

for name, score in zip(names, scores):
    print(name, score)
Enter fullscreen mode Exit fullscreen mode

zip() pairs up elements from two (or more) iterables and lets you loop over them together. It stops when the shortest one runs out.

You can also use it to combine lists into a dictionary:

name_score = dict(zip(names, scores))
# {'Alice': 95, 'Bob': 87, 'Carol': 92}
Enter fullscreen mode Exit fullscreen mode

2. any() and all()

Check conditions across a list without writing a loop.

The verbose way:

scores = [85, 92, 78, 95]
has_pass = False
for s in scores:
    if s >= 80:
        has_pass = True
        break
Enter fullscreen mode Exit fullscreen mode

The clean way:

has_pass = any(s >= 80 for s in scores)
all_pass = all(s >= 80 for s in scores)
Enter fullscreen mode Exit fullscreen mode

any() returns True if at least one item meets the condition. all() returns True only if every item does. Both short-circuit — they stop checking as soon as the answer is known, which makes them fast.


3. enumerate()

Get the index AND value without range(len()).

The clunky version:

fruits = ['apple', 'banana', 'cherry']
for i in range(len(fruits)):
    print(i, fruits[i])
Enter fullscreen mode Exit fullscreen mode

The Pythonic version:

for i, fruit in enumerate(fruits):
    print(i, fruit)
Enter fullscreen mode Exit fullscreen mode

Want to start counting from 1 instead of 0?

for i, fruit in enumerate(fruits, start=1):
    print(i, fruit)
Enter fullscreen mode Exit fullscreen mode

range(len()) is considered a code smell in Python. If you find yourself writing it, reach for enumerate() instead.


4. map()

Apply a function to every item in a list.

The loop version:

names = ['alice', 'bob', 'carol']
capitalised = []
for name in names:
    capitalised.append(name.upper())
Enter fullscreen mode Exit fullscreen mode

With map():

capitalised = list(map(str.upper, names))
Enter fullscreen mode Exit fullscreen mode

Or with a lambda for custom logic:

doubled = list(map(lambda x: x * 2, numbers))
Enter fullscreen mode Exit fullscreen mode

map() is great for simple, single-function transformations. For more complex logic involving conditions or multiple steps, a list comprehension is usually more readable:

capitalised = [name.upper() for name in names]
Enter fullscreen mode Exit fullscreen mode

Both are valid — pick whichever reads more clearly for your use case.


5. collections

Counter, defaultdict, deque — all built in.

The manual counting approach:

words = ['cat', 'dog', 'cat', 'bird', 'cat']
counts = {}
for word in words:
    if word in counts:
        counts[word] += 1
    else:
        counts[word] = 1
Enter fullscreen mode Exit fullscreen mode

With Counter:

from collections import Counter

counts = Counter(words)
# Counter({'cat': 3, 'dog': 1, 'bird': 1})

top_2 = counts.most_common(2)
# [('cat', 3), ('dog', 1)]
Enter fullscreen mode Exit fullscreen mode

collections also gives you:

defaultdict — like a regular dict, but never raises a KeyError. Automatically creates a default value for missing keys.

from collections import defaultdict
d = defaultdict(list)
d['missing'].append(1)  # No KeyError!
Enter fullscreen mode Exit fullscreen mode

deque — a double-ended queue. Much faster than a list for appending or popping from both ends.

namedtuple — a tuple where you can access items by name instead of index.


The Cheat Sheet

Built-in What it does When to use it
zip() Pairs up multiple iterables Looping over two lists together
any() True if at least one item passes Checking if any condition is met
all() True if every item passes Validating a whole list
enumerate() Gives index + value When you need both in a loop
map() Applies a function to each item Simple transformations
Counter Counts occurrences Frequency analysis
defaultdict Dict with default values Avoiding KeyErrors

The Key Takeaway

None of these require installing anything. They’re all part of Python’s standard library, designed specifically for the problems you solve every day.

The difference between a junior and senior Python developer often isn’t the complex stuff — it’s knowing these small tools exist and reaching for them instead of writing loops from scratch.


Which one did you NOT know about before reading this? Comment below 👇

Follow me on Instagram at https://www.instagram.com/techqueen.codes for visual SQL, Python and Snowflake tips every week 💚

Top comments (0)