Wish Python would get 'study' from Perl.
Python built-ins worth learning
41–50 of 69 posts
Re: Python built-ins worth learning
#42If you are reading this, the orange bar at the bottom 5% of my screen is hugely distracting. Please allow us to close it.
Thanks for noting this. I rarely look at my site on mobile and hadn't noticed how big that widget was. I just spent a few minutes making it less visually obtrusive. I may figure out more ways to improve it later.
Re: Python built-ins worth learning
#43I disagree with only one thing in this article. Frozenset is super useful. You should prefer frozenset over set by default imo. Immutable objects are safer to work with, often easier to work with (frozenset is hashable, you can key a dict with it), and sets come up all the time in a lot of work. You can get by with a sorted list, but sets are nicer and faster.
Many of the "don't" callables are useful and I'd say I've used about half (`format` is especially nice as a more flexible version of `str`).
But Python's tendency to mutability and the `set` interface makes frozenset verbose to use & have higher overhead than sets[0]. Usually code is terser and just as clear using sets without mutating them. Which is a shame as of course you lose the safety of enforcing immutability (at runtime but still).
Then again, I guess if you're using a type checker it matters less: it shouldn't let you mutate a `set` if you've typed it as `Set` (rather than `MutableSet`).
[0] IIRC there's only one operation which is specifically optimised for frozensets: copy
Re: Python built-ins worth learning
#44Sets are my #1 favourite Python built-in. I used to have these tedious imperative functions for doing change detection on collections. Then I learned sets and it turned into obvious code like: added = b - a removed = a - b repeated = a & b Etc. Of course this is set theory and not Python specific. But still. Learn sets!
Re: Python built-ins worth learning
#45I always tend to recommend intermediate/advanced programmers to take a look at `functools` and `collections` packages - they are filled with amazing things that you haven't even though you need! My favourites are `functools.partial`, `collections.Counter` and `collections.defaultdict` that are used very often by people who are aware of their existance.
Re: Python built-ins worth learning
#46I always tend to recommend intermediate/advanced programmers to take a look at `functools` and `collections` packages - they are filled with amazing things that you haven't even though you need! My favourites are `functools.partial`, `collections.Counter` and `collections.defaultdict` that are used very often by people who are aware of their existance.
Re: Python built-ins worth learning
#47Luckily it's been added only recently (3.7) :)
Re: Python built-ins worth learning
#48I always tend to recommend intermediate/advanced programmers to take a look at `functools` and `collections` packages - they are filled with amazing things that you haven't even though you need! My favourites are `functools.partial`, `collections.Counter` and `collections.defaultdict` that are used very often by people who are aware of their existance.
I use defaultdict so damn often, it honestly should even be a builtin in my opinion. You also forgot `itertools`, which imo is even more useful than `functools`. I use `chain` and `groupby` quite often. There's also `collections.deque` which is a quick linked list implementation if you need either a stack or a queue.
Re: Python built-ins worth learning
#49Relatedly, I highly recommend Dave Beazley's "Built-In Superheroes" talk: https://www.youtube.com/watch?v=j6VSAsKAj98 I rewatch it every 6 months or so and usually learn a new trick or two.
Any idea what tool he's using for the "slides"?
Re: Python built-ins worth learning
#50Earlier quoted context omitted.
I was really asking about the keywords he typed that showed the "slides" in the terminal. For instance, when he typed in "builtins" at the beginning, it cleared his screen and then showed a quick ASCII art image. I suppose he could have just built these functions, but if there is a tool that he might be using, that would be pretty handy.
no no, that's what i mean: he hacked the REPL up to hell and gone, and is actually using it to run his presentation. It's nuts. See ~04:20 where he briefly alludes to that in the talk.