Peter Norvig: New Python Operators (2023)
betterprogramming.pub
betterprogramming.pub
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. 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.Check this out:
def not_implemented_yet():
... 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.