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

I discovered Rodrigo’s Python drops as I was exploring new features of Python 3.14.0 when it was in beta testing. I was trying to understand the new Placeholder class and found his drop about not only that topic but how it applies to partial.

His explanation was clear, concise and left me understanding a wonderful new Python feature. I’m a highly satisfied Python drops reader.

James Sheldon

β€”James Sheldon, Python drops reader

The "Python Drops" format of one easily digestable topic at a time with code snippets is quite good.

Martin Schorfmann

β€”Martin Schorfmann, Software Developer, Python drops subscriber

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

Nacho Caballero

β€”Nacho Caballero, Python drops subscriber

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

β€”Elias Dorneles, Python drops subscriber

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

Andrew Hartung

β€”Andrew Hartung, Python drops subscriber

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

β€”Roberto Polli, Python drops subscriber

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

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

Quality and fun. Highly recommended!

Nico Belgraver

β€”Nico Belgraver, NavApp, Python drops subscriber

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

Alexandre B A Villares

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

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

David Thorvaldsen

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

Flashcards for visual learners

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

Past tips

  1. Post initialisation in data classes
  2. Recursive structural pattern matching
  3. Unpacking inside comprehensions
  4. Lazy imports
  5. Custom hashable objects
  6. frozendict
  7. Flexible string splitting
  8. Split text into words
  9. Read custom objects from CSV
  10. Multiline input in the REPL
  11. Open standard input
  12. Collapse runs of consecutive spaces
  13. Fixed point
  14. __eq__
  15. at (@) operator
  16. vars and dir
  17. join with a comprehension
  18. Tracking generator expression progress
  19. map to simplify loops
  20. Built-ins any and all
  21. Addition isn't commutative
  22. Split file header from the body
  23. Filter with a predicate
  24. Chaining conditional expressions
  25. Reductions on empty iterables
  26. Protocols and bounded type variables
  27. Clamp
  28. Protocols
  29. Command line arguments
  30. Generalise pairwise with tee
  31. Orderable dataclasses
  32. Print to standard error
  33. Pretty dumping JSON
  34. Parse JSON string into object
  35. Setting the exit code
  36. Implementing pairwise with tee
  37. reveal_type
  38. Expanding regex matches
  39. Patterns in glob search
  40. TypeAlias vs NewType
  41. Convert data to a JSON string
  42. itertools.tee splits iterators
  43. itertools.pairwise
  44. Regex groups with default values
  45. typing.Self
  46. Parse, don't validate
  47. Reading and writing JSON
  48. Cached properties
  49. Base64 encoding
  50. Check if a number is a power of 2
  51. One-shot data compression
  52. typing.NewType
  53. Data class with default mutable value
  54. Fully consume an iterator
  55. Drop into a debugger
  56. ID generator
  57. Type-safe dictionaries
  58. Typing generators
  59. Break from nested loops
  60. Frozen dataclasses
  61. Use set operations with dictionary keys
  62. Create pairs
  63. Read file lines until a separator
  64. Anatomy of a list comprehension
  65. Assigning to list slices
  66. Slicing mnemonic
  67. accumulate with a custom function
  68. Deprecation warnings
  69. Field default factory
  70. Priority queues
  71. Fast exponentiation
  72. Immutable dataclasses
  73. Remove indentation from multiline strings
  74. nwise
  75. Express permutations recursively
  76. Split from both sides
  77. Moving average
  78. Using a list as a stack
  79. Title case
  80. Creating temporary files
  81. assert statements with custom message
  82. Oxford comma
  83. Truthy and Falsy
  84. Private members
  85. strftime vs strptime
  86. Controlled string splitting
  87. Chaining comparison operators
  88. Remote interactive debugging
  89. Check for None functionally
  90. min-heaps and max-heaps
  91. Parse dates from strings
  92. Error handling with multiple types
  93. Grouping digits in the fractional part
  94. asyncio introspection
  95. Custom t-string processing
  96. json CLI
  97. Compression algorithms
  98. Forward references in annotations
  99. Find similar words
  100. copy files
  101. Colour in the REPL
  102. NotImplementedError
  103. Set operations with operators
  104. String formatting field alignment
  105. Cycling over an iterable
  106. NotImplemented
  107. Safe random tokens
  108. Decimals
  109. Using fractions
  110. Regex matches across newlines
  111. Compute partial sums with accumulate
  112. Reduce boilerplate with dataclasses
  113. Alternative constructors as class methods
  114. Read-only attributes
  115. Strict batching
  116. Class and instance attributes
  117. Invertible flags
  118. Find files in a directory
  119. Efficiently count characters in a string
  120. Efficiently count words in a string
  121. Make numbers more readable
  122. Prevent subclassing/overriding
  123. pairwise generalisation
  124. Remove punctuation functionally
  125. Integer literals in multiple bases
  126. Enforce positional arguments
  127. Operate on two lists of numbers
  128. Using properties
  129. Ignore exceptions
  130. Paginate results
  131. All equal
  132. Efficiently extending a list
  133. Safely overriding methods
  134. Dictionary creation idiom
  135. Send data into generators
  136. Double leading underscore
  137. dict.fromkeys
  138. Constant variables
  139. Two-dimensional range
  140. Type hints that refer to functions
  141. Non-greedy regex quantifiers
  142. Add typing to decorators
  143. Dynamic module attribute look-up
  144. map's keyword argument strict
  145. Custom enum search behaviour
  146. Dunder method __missing__
  147. AST parsing
  148. Typing *args and **kwargs
  149. methods __str__ and __repr__
  150. Pretty-printing nested data structures
  151. Filtering Truthy values
  152. Readable object names
  153. Custom containment checks
  154. Match word boundaries
  155. Common __hash__ implementation
  156. Docstring __doc__ attribute
  157. Dynamic width string formatting
  158. Non-local variables
  159. Temporary directories
  160. Timestamp file names
  161. Preserving decorated function metadata
  162. Natural alphabetical sorting
  163. Constrained generics
  164. Caching sets and frozen sets
  165. File modes
  166. Add lists together, fast
  167. Generics syntax
  168. Extracting text data into a dict
  169. Verbose regular expressions
  170. Structural validation and homogenisation
  171. Bulk renaming files
  172. Typing overloads
  173. Undoable iterator with value history
  174. Match an exact dictionary structure
  175. Built-in next with a default value
  176. Match the structure of custom objects
  177. Peek at an iterable
  178. Slicing generators for debugging
  179. Structural pattern matching with dictionaries
  180. File discovery by name pattern
  181. Extract assignments from conditionals
  182. Regex multiline flag
  183. Split strings in two halves
  184. Generator recipe
  185. Concatenate files from handlers
  186. Formatting dates with f-strings
  187. Resolving paths
  188. Named groups in regex
  189. Formatting big numbers
  190. One-shot file I/O
  191. File tail
  192. Idiomatic sequence slicing
  193. Subclassing immutable types
  194. Underscore in the REPL
  195. Ergonomic multiline strings
  196. Structural unpacking
  197. t-strings need processing
  198. Module itertools categorisation
  199. Case-insensitive regular expressions
  200. String constants
  201. Dynamic regex replacements
  202. Random choices
  203. Redacting email addresses
  204. Batching API calls
  205. Dot product idiom
  206. Counting values that satisfy a predicate
  207. Format specifier !r
  208. Read files in chunks
  209. Bounded cache
  210. Longest and shortest
  211. OS-agnostic line splitting
  212. Automatic enumeration values
  213. Global enumeration members
  214. Multi-dictionary
  215. Typing iterables instead of lists
  216. Inline lists and tuples
  217. Transpose a list of lists
  218. Normalise strings by removing accents
  219. Most recently-modified file
  220. Enumerations of string values
  221. Return value of a generator
  222. Use Literal for options
  223. Flag enumerations
  224. Enforce keyword arguments for options
  225. Notify parent class when subclassing
  226. Dynamic attribute manipulation
  227. Longest word in a string
  228. Chain multiple dictionaries
  229. Set operations with dict.keys()
  230. Current date and time
  231. Dunder attribute __file__
  232. Self-debugging f-strings
  233. Immutable dictionary
  234. Create context managers with contextlib.contextmanager
  235. Type statements
  236. Round to pretty whole numbers
  237. Multiple options in a single case statement
  238. String prefixes and suffixes
  239. Run-length encoding
  240. Count characters in a file
  241. Remove punctuation from a string
  242. map with multiple arguments
  243. Schedule cleanup actions
  244. Unique elements from a list
  245. Last element that satisfies a condition
  246. First element that satisfies a condition
  247. Parsing integers from different bases
  248. Type unions with the vertical bar in isinstance
  249. Case-insensitive string comparisons
  250. 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