6 ms·
They got rid of the super ugly [:] but introduced a new ugliness.. | and |= operators for dictionaries. Why is this so important that this needs special operato
by ju-st 6y ago
They got rid of the super ugly [:] but introduced a new ugliness.. | and |= operators for dictionaries. Why is this so important that this needs special operators? Python should be readable by everyone who can understand English. I hate when languages keep inventing hieroglyphs, twisting my fingers to type |= takes even longer than typing .join.
- renewiltord 6y agoYou can still do `a.update(b)`
- duckerude 6y agoThe existing alternative to `a | b` was {**a, **b} You could see this as an improvement.
- edgyquant 6y agoAs someone who started out in C I love the pointer style syntax
- rmtech 6y agoOh my god yes.
- philsnow 6y agoas pointed out elsewhere in this thread, `"a" or "b"` evaluates to "a", which kind of makes me think that `a | b` (with a and b as dicts) would take values for overlapping keys from a, not from b. The dict literal with dict-splats conveys a sense of ordering that makes the behavior of taking values for overlapping keys from the lattermost dict make more sense to me.
- meowface 6y agoThis is my favorite change in this release and cause me to upgrade to the RC version a few days ago. It's a huge QoL improvement for so much code I write. I'm also a fan of the walrus operator. These are small, rare, clear, useful, idiomatic new features, in my opinion.
- smitty1e 6y agoIt is outstanding that that the new features have an audience. One frets that Python could become a victim of 'featuritis' as the devs try to shop for a new kitchen sink for each release.
- fireattack 6y agoI personally feel walrus operator is a much more prominent improvement, considering how prevalent it can be used (like, I use it in almost every single `re.search()`, and at least half of conditional list comprehensions and `while`), while I don't find the old way of updating dict (`{a, b}` etc.) too bad. But of course, both are very welcomed!
- amelius 6y ago> They got rid of the super ugly [:] What do you mean by that? Can't we clear a list by doing: L[:] = [] (useful when L is defined in another scope, or when you want to keep a reference to the same list object) Unfortunately it's not possible to search for "[:]", so pointers appreciated
- ed25519FUUU 6y agoWait, why not just L.clear()?
- amelius 6y agoGood point. But you might still want e.g.: L[1:] = []
- ju-st 6y agoI just meant that you need the "[:]-operator" less often because of the new methods removeprefix, not that the thing is completely removed.
- kevin_thibedeau 6y agoThey already existed for sets and some people want dicts to have analogous behavior.
- irrational 6y agoI feel the same way about -> in JavaScript. You would think after all these years I'd have come around by now. Nope, I'm still pissed off about that decision.
- gecko 6y agoHuh? What's this do in JavaScript? (No sarcasm; I'm mostly in this ecosystem, but I have no idea what this is in reference to.)
- irrational 6y agoThey are called arrow functions (-> looks a bit like an arrow).
- ZephyrBlu 6y agoIt's confusing to write it like -> because the actual operator is =>, which is close but not the same.
- arthurcolle 6y agoisn't it =>
- jakogut 6y agoI find this operator intuitive and idiomatic. It's widely understood and used as a binary OR operator in many languages, and it's easy to understand its functionality when both operands are dictionaries.
- nneonneo 6y agoIt’s also already an established part of the set syntax - it’s been possible to ^, | and & sets for a while now (symmetric difference, union and intersection). While not all of those make sense for dicts, | for union does and is quite intuitive.
- sgdpk 6y agoIt's also consistent with the set notation, which makes it easier to remember. Dict keys already kind of work like a set, this extends the behavior to deal with the values as well.
- saiojd 6y agoIt's not introduced at all, its already there for sets