4 ms·
Peter Norvig: New Python Operators (2023)
- fritzo 3y agoHonestly though, I wish min and max were treated as first class citizens, the way addition and multiplication are. In-place max=, min= operators would be super useful, both in Python in general and in ML flavored libraries in particular (e.g. numpy, torch).
- deleted 3y ago[deleted]
- ra 3y agoThis is last year's April fools joke?
- geor9e 3y agoEverything in it is true, though.
- MathMonkeyMan 3y agoIt took me longer than I'd like to admit. The lapping cat operator is truly inspired. Being a sucker for for pattern matching, I'm more likely to write foo, = seq or foo, *_ = seq than assert len(seq) == 1 foo = seq[0] or foo = seq[0] Though I vaguely call past colleagues disagreeing, or at least insisting on parens around the "foo," in the first one.
- milliams 3y ago(2023)
- behnamoh 3y agoI wish Python had null coalescing, custom operators, macros, and optional static typing enforcement at runtime (without needing mypy).
- terr-dav 3y ago>...and optional static typing enforcement at runtime (without needing mypy). Check this out: https://beartype.readthedocs.io/en/latest/ https://beartype.readthedocs.io/en/latest/
- unwind 3y agoThat was fun, but in a semi-scary way. I have major respect for the source, so when Mr Norvig states that this (the "Emphasis Operator"): sigh = 3 ['oh', 'good', 'grief', *sigh* ['drat']] results in: ['oh', 'good', 'grief', 'drat!', 'drat!', 'drat!']]. I first believed it, then doubted it, then tested it, and then came here to comment. Those exclamation points are not there in the output, which I was very relieved to see. Phew, but I also think it would be a good idea to fix it.
- fred256 3y agoSemi-related, in a past life, I used ... to indicate "not implemented yet": def not_implemented_yet(): ...
- IgorPartola 3y agoI knew it was a joke when I saw the first one: items *= 0. # items is now empty But didn’t explain whether it was emptied in place or if a new list object was assigned to items.
- JohnDeHope 3y agoThese are cute, but this is also one of the reasons why I can never get into python. It's had too much stuff tossed into it.