As someone who teaches Python programming for a living, I’ve spent the last few years wrestling with the educational implications of AI. I’m changing everything I do to adjust to our new AI reality, experimenting with new ideas, including my AI-based Socratic tutor (https://practice.lernerpython.com/). I keep what works, throw away what doesn’t, and then try…
July and August are often when people take a break or go on vacation. But for me, this summer has been super busy, full of writing and improving LernerPython based on feedback I’ve gotten from people around the world. And so, I’m here with some big changes I’m making at LernerPython World Headquarters: 1. AI…
If you want to get better at Pandas, the hard part isn’t finding tutorials. It’s finding problems worth solving. Most exercises hand you a tidy little table of five rows and ask you to sum a column — which teaches you the syntax, but nothing about the job. For the last 3.5 years, I’ve written…
Once you import a Python module, a second import won’t reload it. That’s usually good. But what if you want to? (Common in development and debugging.) This forces the reload.
You import a Python module with the variable you’ll define, not a filename. “import mymod” tells Python to find mymod.py in each dir in sys.path. The first directory is ” (the empty string) — i.e., the directory where the program is running (i.e., not where it was defined).
Want the unique key-value pairs from two Python dicts? dict.items() returns a set-like object: This returns the unique key-value pairs: {(‘b’, 20), (‘a’, 10), (‘d’, 40), (‘c’, 30)}
Want the unique keys from two Python dicts? dict.keys() returns a set-like object, supporting set operators:
Differences between dict.pop and dict.popitem in Python: dict.pop: – removes a pair based on a key– returns removed value– optional 2nd arg is returned if key isn’t there dict.popitem: – no arguments– returns the most-recently-inserted pair– returns (key, value) tuple
To remove a key-value pair from a Python dict, use dict.pop: Or… pass a second argument to dict.pop. You’ll get it instead of an exception:
Merge two Python dicts with | which returns a new dict. Conflicts? The right-side dict gets priority: d1 | d2 # {‘a’: 10, ‘b’: 100, ‘c’: 200, ‘d’: 300}d2 | d1 # {‘b’: 20, ‘c’: 30, ‘d’: 300, ‘a’: 10}