Sometimes I see questions closed as "duplicates" of a more general question. Latest example asked for finding the most common value which was closed as duplicate of finding the 10 most common values.
(Edit: The list of "dupe targets" for that question just got extended, but the general issue I ask about here remains.)
I don't think that's right. Finding the single most common value is a special case and it allows better solutions which take advantage of that. They can be simpler and they can be more efficient. Yes, the more general solutions of the more general question can be applied, but that's not optimal then.
I was told to post a special case answer under the general case question, even though it doesn't answer that question. Should I really? I think that would be wrong. And if it's indeed wrong, then is it appropriate to close special case questions as duplicates of more general questions so that answers taking advantage of the special case can't be posted anywhere?
Edit 2 because apparently nobody can imagine special case solutions possibly being better than general case solutions:
Do you think sorted(mylist)[0]
is the best way to find the smallest value in mylist
? Don't you think that's a bad way? Don't you think people should be taught min(mylist)
for that? Do you think people trying to point out min
for that should be shut up? Do you think they should instead tell min
to people who asked how to find the tenth-smallest element? That's what this was like.
The "the most common value" case is just like that, with Counter(mylist).most_common(1)[0][0]
vs mode(mylist)
. Don't you think the latter is much simpler and cleaner? It even comes with appropriate error detection/handling. And while that one isn't faster (because currently it's implemented using Counter.most_common
), there are faster ones, for example max(mylist, key=Counter(mylist).get)
.
statistics.mode
ormax
right away doesn't answer the "top 10" question, and it's not clear at all how it could be helpful for that. How would you use them to solve the "top 10" question? I don't see any reasonable way.