Python Tuples: Unpacking, Dict Keys and the Trailing-Comma Trap
How to use Python tuples well: creating them, unpacking, using them as dict keys, named tuples, and the one-element and += gotchas that catch everybody.
Search
9 articles matched your search.
How to use Python tuples well: creating them, unpacking, using them as dict keys, named tuples, and the one-element and += gotchas that catch everybody.
Lists vs tuples in Python beyond 'one is mutable': the real differences in hashability, memory, safety and intent, plus a decision rule that works in practice.
Python basics with runnable examples: names and objects, lists, dicts and sets, control flow and comprehensions, plus the traps behind most beginner bugs.
How to write Python functions: arguments, defaults, *args and **kwargs, scope, type hints and docstrings, plus the mutable default bug everyone hits once.
NumPy indexing and slicing explained: why editing a slice changes your original array, when masks and fancy indexing copy instead, and how to avoid both bugs.
Python strings in practice: f-strings, slicing, the methods worth memorising, why += loops slow down, and the encoding default that breaks scripts on Windows.
Advanced Python regex with tested output: named groups, lookarounds, re.sub with a function, and why a 24-character input made (a+)+$ run for 10 seconds.
Iterators and generators in Python explained: yield, pipelines that stream big files in flat memory, itertools, and why a generator silently runs only once.
A Python lambda function is a one-expression anonymous function. Learn where it helps (sort keys, callbacks), when def wins, and the loop bug it causes.