Python drops πŸπŸ’§

A daily drop of Python knowledge

Become smarter about Python

Get a short, actionable Python tip each day. Tips are short (under 100 words), actionable (you can apply them right away) and they're also sent as a flashcard, ideal if you're a visual learner.

Become smarter about Python πŸπŸ’§

What readers have to say

Nacho Caballero

Rodrigo is a consistent source of generous, high‑quality technical insights about the [Python] language we know and love.

β€” Nacho Caballero – Python drops subscriber

Elias Dorneles

I very much enjoy receiving Rodrigo's Python tips on my email. They're bite-sized and informative, just great as a daily dopamine hit!

β€” Elias Dorneles – Python drops subscriber

Andrew Hartung

The diagrams are always so well done they don't even need supporting text.

β€” Andrew Hartung – Python drops subscriber

Roberto Polli

I always recommend Rodrigo's posts to friends and colleagues.

Newcomers will learn Python concepts in an engaging way, and experienced programmers can refresh their knowledge and even learn something new about latest Python releases.

Thanks Rodrigo!

β€” Roberto Polli – Python drops subscriber

Sean

This is a great daily read regardless of your Python level. Within a minute or two; you are introduced to a language component or mechanism, a common use case for it, and example code demonstrating it.

β€” Sean – Staff Engineer for an American Telco, Python drops subscriber

Nico Belgraver

Quality and fun. Highly recommended!

β€” Nico Belgraver – NavApp, Python drops subscriber

Alexandre B A Villares

Rodrigo, your "tip cards" have been smashing, elegant and informative! Thank you for sharing them!

β€” Alexandre B A Villares – Python teacher, Python drops subscriber

David Thorvaldsen

I really enjoy your Python drops! So much new exposure to what's possible with the language!

β€” David Thorvaldsen – AI/ML Data Scientist @ Caterpillar Inc., Python drops subscriber

Robert Lucente

Love the short to the point code snippets. Then you really bring it home with graphics. Just awesome.

β€” Robert Lucente – Author of The Bit Plumber, Python drops subscriber

Roberto

Very interesting, looks like every time I read your posts I learn something new!

β€” Roberto – Python drops subscriber

Flashcards for visual learners

A horizontal composition of diagrams of 5 older tips.
Flashcards from previous tips.

Past tips

  1. NotImplementedError
  2. Set operations with operators
  3. String formatting field alignment
  4. Cycling over an iterable
  5. NotImplemented
  6. Safe random tokens
  7. Decimals
  8. Using fractions
  9. Regex matches across newlines
  10. Compute partial sums with accumulate
  11. Reduce boilerplate with dataclasses
  12. Alternative constructors as class methods
  13. Read-only attributes
  14. Strict batching
  15. Class and instance attributes
  16. Invertible flags
  17. Find files in a directory
  18. Efficiently count characters in a string
  19. Efficiently count words in a string
  20. Make numbers more readable
  21. Prevent subclassing/overriding
  22. pairwise generalisation
  23. Remove punctuation functionally
  24. Integer literals in multiple bases
  25. Enforce positional arguments
  26. Operate on two lists of numbers
  27. Using properties
  28. Ignore exceptions
  29. Paginate results
  30. All equal
  31. Efficiently extending a list
  32. Safely overriding methods
  33. Dictionary creation idiom
  34. Send data into generators
  35. Double leading underscore
  36. dict.fromkeys
  37. Constant variables
  38. Two-dimensional range
  39. Type hints that refer to functions
  40. Non-greedy regex quantifiers
  41. Add typing to decorators
  42. Dynamic module attribute look-up
  43. map's keyword argument strict
  44. Custom enum search behaviour
  45. Dunder method __missing__
  46. AST parsing
  47. Typing *args and **kwargs
  48. methods __str__ and __repr__
  49. Pretty-printing nested data structures
  50. Filtering Truthy values
  51. Readable object names
  52. Custom containment checks
  53. Match word boundaries
  54. Common __hash__ implementation
  55. Docstring __doc__ attribute
  56. Dynamic width string formatting
  57. Non-local variables
  58. Temporary directories
  59. Timestamp file names
  60. Preserving decorated function metadata
  61. Natural alphabetical sorting
  62. Constrained generics
  63. Caching sets and frozen sets
  64. File modes
  65. Add lists together, fast
  66. Generics syntax
  67. Extracting text data into a dict
  68. Verbose regular expressions
  69. Structural validation and homogenisation
  70. Bulk renaming files
  71. Typing overloads
  72. Undoable iterator with value history
  73. Match an exact dictionary structure
  74. Built-in next with a default value
  75. Match the structure of custom objects
  76. Peek at an iterable
  77. Slicing generators for debugging
  78. Structural pattern matching with dictionaries
  79. File discovery by name pattern
  80. Extract assignments from conditionals
  81. Regex multiline flag
  82. Split strings in two halves
  83. Generator recipe
  84. Concatenate files from handlers
  85. Formatting dates with f-strings
  86. Resolving paths
  87. Named groups in regex
  88. Formatting big numbers
  89. One-shot file I/O
  90. File tail
  91. Idiomatic sequence slicing
  92. Subclassing immutable types
  93. Underscore in the REPL
  94. Ergonomic multiline strings
  95. Structural unpacking
  96. t-strings need processing
  97. Module itertools categorisation
  98. Case-insensitive regular expressions
  99. String constants
  100. Dynamic regex replacements
  101. Random choices
  102. Redacting email addresses
  103. Batching API calls
  104. Dot product idiom
  105. Counting values that satisfy a predicate
  106. Format specifier !r
  107. Read files in chunks
  108. Bounded cache
  109. Longest and shortest
  110. OS-agnostic line splitting
  111. Automatic enumeration values
  112. Global enumeration members
  113. Multi-dictionary
  114. Typing iterables instead of lists
  115. Inline lists and tuples
  116. Transpose a list of lists
  117. Normalise strings by removing accents
  118. Most recently-modified file
  119. Enumerations of string values
  120. Return value of a generator
  121. Use Literal for options
  122. Flag enumerations
  123. Enforce keyword arguments for options
  124. Notify parent class when subclassing
  125. Dynamic attribute manipulation
  126. Longest word in a string
  127. Chain multiple dictionaries
  128. Set operations with dict.keys()
  129. Current date and time
  130. Dunder attribute __file__
  131. Self-debugging f-strings
  132. Immutable dictionary
  133. Create context managers with contextlib.contextmanager
  134. Type statements
  135. Round to pretty whole numbers
  136. Multiple options in a single case statement
  137. String prefixes and suffixes
  138. Run-length encoding
  139. Count characters in a file
  140. Remove punctuation from a string
  141. map with multiple arguments
  142. Schedule cleanup actions
  143. Unique elements from a list
  144. Last element that satisfies a condition
  145. First element that satisfies a condition
  146. Parsing integers from different bases
  147. Type unions with the vertical bar in isinstance
  148. Case-insensitive string comparisons
  149. zip's keyword argument strict

Refer readers, access the tip backlog

The mathspp drops πŸπŸ’§ newsletter is free. That's 5 tips per week, for free.

If you refer your friends and colleagues to the mathspp drops πŸπŸ’§ newsletter, you can earn rewards. For example, you can earn access to the backlog of tips (started on the 4th of March of 2025), which is available as an e-book and as a set of flashcards.

To refer friends, check the instructions on the bottom of every tip email you receive.

E-book version

The backlog of tips (started on the 4th of March of 2025) can be purchased as an e-book (in PDF and EPUB formats) and as a PDF with the set of flashcards.

Subscribe