3 ms·
re's API sucks but I'm looking forward to safe dictionary access with assignment as well. No more if my_map.get(key) is not None: // do something with my_
by fjp 7y ago
re's API sucks but I'm looking forward to safe dictionary access with assignment as well. No more
if my_map.get(key) is not None:
// do something with my_map[key]
- DonaldPShimoda 7y agoHere the "better" solution (imo) would be support for pattern matching: match my_map.get(key): case None: // do thing (or nothing, i.e., pass) case Some(val): // do other thing Scala seems to have figured out how to get pattern matching over arbitrary data (i.e., not statically-defined algebraic datatypes). I'd like to see this come to Python. (Normally I'd fight for pattern matching to always provide static type safety guarantees, but in Python it seems completely reasonable to omit such checks.) EDIT: But you're absolutely right that this is a place where assignment expressions will be used regularly, so thank you for pointing that out!