@
Python Tip #329 (of 365): Make sure your tests can actually fail. π§΅ This test passes no matter what calculate_total returns: def test_total(): total = calculate_total([3.50, 13.75]) assert (total == 17.25, "wrong total") #Python #DailyPythonTip
@
βPython's break stops the whole loop, but continue only stops a single iteration of a loop.β Read more π https://pym.dev/breaking-out-of-a-loop/ #Python
@
Python Tip #328 (of 365): Use a linter and an auto-formatter. π§΅ Linters are stylistic proofreaders for your code. They spot inconsistencies, and sometimes bugs: $ ruff check greetβ.py F401 [*] `os` imported but unused --> greetβ.py:1:8 help: Remove unused import: `os` #Python #DailyPythonTip
@
βPython 3.15 also includes even more improvements to error messages, and many of them are aimed at folks coming to Python from other programming languages.β Read more π pym.dev/python315/ #Python https://pym.dev/python315/
@
πΊοΈ November 24, 2026 5/5 countries in 8/13 guesses π’π’π’π‘π whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
My ninth annual compilation of Python-related Black Friday & Cyber Monday sales is now published. I now know of 6 sales that are currently live or coming up. If you hear of a sale related to Python learning that isn't on the list, let me know. https://treyhunner.com/2026/11/python-black-friday-and-cyber-monday-sales-2026/
@
Python Tip #327 (of 365): Loop over neighboring items with pairwise. π§΅ Do this: for day, next_day in pairwise(days): print(day, next_day) Not this: iterator = iter(days) day = next(iterator) for next_day in iterator: print(day, next_day) day = next_day #Python #DailyPythonTip https://pym.dev/avoid-indexes-in-python/#other-looping-helpers-to-help-avoid-indexing
@
Ever learned a Python feature, used it once, and had to look it up again six months later? I spent a lot of this year making something to try to fix that: Daily Recall. Until Nov 30, you can get lifetime access to it and everything else in Python Morsels. Details at pym.dev/lifetime ππͺ
@
πΊοΈ November 23, 2026 5/5 countries in 5/13 guesses π’π’π’π’π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #326 (of 365): When you don't care about a dictionary's values, use a set instead. π§΅ Finding yourself making a dictionary where the values are the same as the keys? color_options = {"purple": "purple", "blue": "blue", "green": "green"} #Python #DailyPythonTip https://pym.dev/practical-uses-of-sets/#sets-are-like-dictionaries-without-values
@
βThe first person to enter a queue will be the first person to reach the front of the queue.β Read more π https://pym.dev/stacks-and-queues/ #Python
@
πΊοΈ November 22, 2026 5/5 countries in 6/13 guesses π‘π’π’π’π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #325 (of 365): Avoid returning defaultdict objects. π§΅ A defaultdict is handy while building a dictionary: by_color = defaultdict(list) for item in items: by_color[item.color].append(itemβ.name) But once you're done, it'll keep auto-creating missing keys. #Python #DailyPythonTip https://pym.dev/default-dictionary-values/
@
Until November 30, I'm offering lifetime access to Python Morsels. I just published a post about this. https://treyhunner.com/2026/11/lifetime-access-sale-2026/
@
πΊοΈ November 21, 2026 5/5 countries in 6/13 guesses π’π‘π’π’π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
βIf some strictly unnecessary syntax makes code more readable, don't delete it.β Read more π https://pym.dev/unnecessary-syntax/ #Python
@
Python Tip #324 (of 365): Sort a dictionary with dict(sorted(d.items())). π§΅ >>> counts = {"sandwiches": 10, "drinks": 20, "oranges": 7} >>> dict(sorted(counts.items())) {'drinks': 20, 'oranges': 7, 'sandwiches': 10} #Python #DailyPythonTip https://treyhunner.com/2021/11/how-to-sort-a-dictionary-in-python/
@
Python Morsels lifetime access is back on sale for the next week. Lifetime access is best for folks who Python regularly and hope to improve their skills year over year. If you haven't tried Daily Recall yet, check out the quick demo on the sales page. Sale ends Monday, Nov 30. #Python https://pym.dev/lifetime-access-sale?utm_source=bluesky&utm_campaign=bf26-social
@
πΊοΈ November 20, 2026 5/5 countries in 7/13 guesses π π’π’π’π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #323 (of 365): You're allowed to rely on dictionary order. π§΅ >>> fruit_counts = {"apple": 2, "banana": 4, "mango": 1} >>> for fruit in fruit_counts: ... print(fruit) ... apple banana mango Dictionaries maintain the insertion order of their keys. #Python #DailyPythonTip
@
βPython's textwrap module has a wrap function for wrapping text.β Read more π pym.dev/wrapping-text/ #Python https://pym.dev/wrapping-text/
@
It feels like forever since I've had 5 greens. Whereabouts Daily πΊοΈ November 19, 2026 5/5 countries in 5/13 guesses π’π’π’π’π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #322 (of 365): Remove a key that might not exist with a default pop value. π§΅ Do this: session.pop("username", None) Not this: if "username" in session: del session["username"] The dictionary pop method deletes a key and returns its value. #Python #DailyPythonTip
@
βSets and dictionaries are often great for quick containment checks, but they don't work when our containment checks are inexact.β Read more π pym.dev/binary-search/ #Python https://pym.dev/binary-search/
@
πΊοΈ November 18, 2026 5/5 countries in 7/13 guesses π‘π’π’π‘π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #321 (of 365): Loop over dictionary keys explicitly with keys(). π§΅ >>> counts = {"computers": 2, "cats": 1, "ducks": 3} >>> for name in counts.keys(): ... print(name) ... computers cats ducks #Python #DailyPythonTip
@
πΊοΈ November 17, 2026 5/5 countries in 7/13 guesses π’π‘π’π‘π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #320 (of 365): Use "in" to check whether a dictionary has a key. π§΅ Do this: if color not in quantities: print(f"Uh oh! There's no value for {color}") Not this: if not quantities.get(color): print(f"Uh oh! There's no value for {color}") #Python #DailyPythonTip https://pym.dev/using-dictionaries-in-python/#key-check
@
πΊοΈ November 16, 2026 5/5 countries in 6/13 guesses π’π’π‘π’π’ whereabouts.earth/daily/ #Whereabouts https://whereabouts.earth/daily/
@
Python Tip #319 (of 365): Name your regular expression capture groups. π§΅ Capture groups are neat, but it can be confusing figuring out what the group numbers represent: >>> match = reβ.search(r"(\d{2})/(\d{2})/(\d{4})", "from 12/22/1629") >>> match[3] '1629' #Python #DailyPythonTip