|
|
|
|
|
by i_am_programmer
1671 days ago
|
|
This kinda reads as the writer doesn't actually know Python all that well, these definitely aren't Python antipatterns. Lists and Sets are not the same data structure, obviously Sets are faster for finding if an item exists or not, but Sets are immutable and you can't have duplicate values like in a list. You can't substitue Sets for Lists for everything. What if I'm iterating over a list where I need to keep duplicates? Also, who wraps a try except over a dictionary? Just use .get(), it defaults to None instead of raising a KeyError and even let's you pass a default value as the 2nd argument, .get("a", "hello"). The most basic google search could have helped with these. |
|
2. Yes, you can use .get(), I was trying to demonstrate the idea of EAFP, and thought that the dictionary snippet might serve as a good example, we probably disagree.