Comprehensions in Python

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified
Search for a command to run...

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified
No comments yet. Be the first to comment.
Concise guides to Python features and patterns most useful for data engineering — from built-ins to standard library modules.
One thing you might encounter in Python are the "dunder" (because of the double underscore before and after their name) or "magic" methods, because they're special. You should have surely seen the '__init__' method in Python code. Now, 'dunder' metho...
Here's a useful Dataform concept: pre_operations and post_operations. As the name implies, these represent a set of actions that run before and after the main operation (table, view, or SQL operations

BigQuery has always been a SQL engine for tabular data. Object tables add an interesting twist to that. Instead of rows containing values, an object table gives you one row per file — pointing at da

Query your data lake with warehouse-grade security and performance — without moving a single file.

Ever run a heavy BigQuery SQL query, processed gigabytes of data — and then accidentally closed the tab or forgot to save the results? 😬 Don't re-run it. Your results are still there. BigQuery automa

You can use query parameters in BigQuery hashtag#SQL (now in the console as well!) — but how are they different from variables, and when should you use each? Both parameters and variables act as place

title: "Comprehensions in Python" seoTitle: "Python Comprehensions: List, Dict, Set, and Generator" seoDescription: "A concise guide to list, dictionary, set, and generator comprehensions in Python with practical examples. Learn when comprehensions improve code..." datePublished: Wed Dec 06 2023 22:18:07 GMT+0000 (Coordinated Universal Time) cuid: clpubyrlh000008jn7u8cdbhd slug: comprehensions-in-python cover: https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/nVqNmnAWz3A/upload/810ea2a007ec5ba0b522c1d4e521bf48.jpeg tags: programming-blogs, python, data-engineering, programming-tips
Do you work with Python comprehensions in your day-to-day?
Comprehensions are a straightforward way to create lists, sets, dictionaries and generators from existing iterables - such as lists or tuples.
They allow for short, concise notation as opposed to loops. As usual, it's important to think about code readability and not overuse them.
See below a quick worksheet with examples of common comprehensions in Python, applied in a simple scenario - computing number squares.
Thanks for reading!
Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.
Enjoyed this? Here are some related articles you might find useful: