There's one thing I've been REALLY enjoying using uv for: writing standalone Python scripts that require third-party dependencies. More on my current (somewhat conservative) uses for uv: #Python #uv
"But there's an even better way to check whether one string is the substring of another string." Read more 👉 #python
Every Wednesday morning, I share a Python tip via email. I've been doing this since June 1, 2022. If you'd like to read a Python tip from me each week, you can subscribe at https://trey.io/news 🐍💌 #Python
Creating a singleton class by making a custom constructor does work, but it might seem a little bit misleading to someone using this class. Read more 👉 #Python
When debugging in #Python, I prefer this: >>> vars(some_obj) Over this: >>> some_obj.__dict__ Why? 1. When possible, I prefer high-level operations over direct dunder access 2. It's 2 fewer characters! And yes I also use dir(), but the two have slightly different uses and both can be handy! More on dir & vars:
Just realized an odd coincidence from a 13-year-old open source contribution. I contributed the "ping" command to the WINE command prompt to make it simply sleep (DOS didn't have sleep so batch files often used ping to sleep). This OSS contribution was part of a homework assignment. I just realized today that my professor for that class (Dr. Paul Eggert) was one of the two authors of the GNU/Linux sleep utility (along with many other utilities he helped write). 🤯 #OpenSource
What's a fairly fundamental #Python feature that you're glad you've embraced? Could be a feature that some other programming languages don't have or one whose purpose you didn't really understand when you first learned about it.
Recursion is most often useful when the problem you're solving involves traversing or constructing a tree-like structure. Read more 👉 #recursion #python
Need to remove duplicates from a list? >>> items = [2, 1, 6, 4, 2, 4, 7] This works: >>> dedup = set(items) But item order will be lost: >>> dedup {1, 2, 4, 6, 7} If the original order should be maintained, you can use the keys of a dictionary: >>> dedup = list(dict.fromkeys(items)) Dictionary keys maintain their insertion order in #Python: >>> dedup [2, 1, 6, 4, 7] More on that last approach:
Last day to get Python Jumpstart for 50% off. 🐍 There's a 30 day money-back guarantee, no questions asked. 💰 #Python #CyberMonday