News for hackers. Stuff that matters.
Re:Python Common Anti-Patterns by i_am_programmer on Tuesday November 16, 2021 @05:19AM (#29238907)
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.

Re:Python Common Anti-Patterns by devev on Tuesday November 16, 2021 @08:19AM (#29240192)
1. I wasn't intending to make it sound like you should substitute all your Lists to Sets as I am well aware of the differences between them. I was trying to convey that on some specific cases Sets are faster than lists, whether if it's obvious or not to everyone, I don't know.

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.

Re:Python Common Anti-Patterns by Doxin on Tuesday November 16, 2021 @10:33AM (#29241641)
nitpicky: sets aren't immutable. frozensets are.