18

The specific Stack Overflow question motivating my question here is How do I count the occurrences of a list item?.

As you can see, this is an extremely important question for . As of writing, it has 2.6 million views, a score around +2000, and over 200 linked questions.

The problem is, it has been treated in the answer section as if it were two completely separate questions simultaneously. One question is "how do I count how many times a given value appears in a list?" The other is "how can I count the number of times that each element that appears in the list, appears?" (In other words: how can one tally the elements, or - with slightly stretched definitions - make a histogram?)

This is not the fault of the person who originally asked the question. I checked the revision history and only minor fixes for grammar/spelling etc. have ever been made. The question was always only ever asking about counting appearances of a single value. It really is as simple as using the .count method and doesn't require any elaboration. Everything about collections.Counter etc. is unrelated, added on the whim of the answerers.

It's important, in my view, to have canonicals for both questions. The first isn't actually asked very often, because it's perhaps a little too basic - pretty much any tutorial that explains what lists are will cover this material in nearly the same breath. But it's still an important reference. The second question is asked all the time - while trying to find the canonical to close one, using a search engine, I stumbled on other attempts from within the last 24 hours.

Because the answers are there, though, I assume that this has been getting used as the canonical for the more complex, commonly asked, collections.Counter question. If I had a time machine, I could go back to 2010 and fix this; but now these off-topic answers have thousands of upvotes. Dupe-hammering with this feels awful, because the question looks clearly different from what people are asking in most cases - so they will protest that it isn't a duplicate.

Is there anything we can do to disentangle this mess?

19
  • 3
    I doubt there is much to do here... Apparently people still find those answers useful, maybe by weird search terms they actually look for the Counter answer but happen to search the count one. Who knows... I'm at least happy that the top-voted, accepted answer is about count so at a first glance the Q&A couple looks OK (it appears first both on counts and trending sorts). The question probably got popular with time and people wanted to chime in on the rep farm...
    – Tomerikoo
    Commented Jul 28, 2022 at 7:26
  • 4
    "Everything about collections.Counter etc. is unrelated" - Eh? By using this collection one could create a dictionary of items' counters, and by using a "single value" as a key get the counter for this specific value. Yes, this approach could be somehow slower (and more memory consuming) than a simple .counter, but it is still a solution. I find no problem about existing the answers, which suggest collections.Counter.
    – Tsyvarev
    Commented Jul 28, 2022 at 8:05
  • I feel like these are somewhat related. A common way to divide problems is to go from "how do I do <task> for all items" to "how do I do <task> for one item" and then repeat that. So the .count vs Counter problems are a tightly coupled XY pair and it makes sense to answer both at ones. Admittedly, the key is both – answers covering the "hidden" question should still cover the actual question as well. Commented Jul 28, 2022 at 9:03
  • 3
    Oh my. After going through the answers, I have to say the Counter answers are amongst the good ones. The loop-and-.count answers, the numpy-if-the-stars-align-just-right-but-I'm-not-saying-how answers, the let's-reimplenent-Counter answers – there is a lot of bad advice there. Commented Jul 28, 2022 at 9:28
  • 3
    "... the question is fine...", yeah...!, this is a "lazy-newbie-low-quality-codez-plzzz" Question about some basic Functionality, vaguely formulated in 1 Sentence from some Asker who couldn't get bothered to check any Documentation for available Commands, with no Example (of Input + (desired) Output), and that got 20k Rep to the Asker. Asked "today", it would garner 20 Downvotes per 10 minutes... => No "wonder" it got interpreted in different ways by the Answerers... // => Maybe improve the Question already and make it "a bit more precise"...
    – chivracq
    Commented Jul 28, 2022 at 12:32
  • 6
    @chivracq The reason the same question would be so poorly-received today, 12 years later, is because questions like this are definitely duplicates if they are asked today. It doesn't mean that such questions aren't useful (thousands of upvoters think they are), only that they already exist by now.
    – kaya3
    Commented Jul 28, 2022 at 12:36
  • 1
    @kaya3, yeah I know, but SO wants to be "a Repository of Quality Q/A Pairs", I find it nearly shameful to (have to) use such Low Quality Questions as Dupe Target(s)... (The Thread definitely has some Value, thanks to all the different Answers, but the Question itself is Low Quality...)
    – chivracq
    Commented Jul 28, 2022 at 12:44
  • 3
    @chivracq Many of the site's most important questions look like this one. I/O examples hardly seem necessary to understand what is expected. In fact, the other canonical is arguably made worse by the example code, because the output specification is unnatural for the problem (and makes it unclear: will the values always be integers? If so, should the output skip slots for integers that aren't present in the input? Why do they start at 1 instead of 0?) Commented Jul 28, 2022 at 16:55
  • @KarlKnechtel, by "most important" you mean "most popular" (and with the highest Scores)... If they are "important", then make those Threads with a Wiki Status (both on the Question + all Answers), and do some "Clean-up", keeping only the "best" 10 or maybe 20-max Answers that "really" have/add some Value (and Quality), with a new Implementation/Solution that was not posted already...
    – chivracq
    Commented Jul 28, 2022 at 17:27
  • 2
    yes, popularity of Stack Overflow questions makes them important, because it's the best predictor (that I have, anyway) of future traffic - which directly translates into the number of people who would be impacted in the future by changes to the question. Commented Jul 28, 2022 at 17:36
  • 2
    The other thing to note here is that the question has value because the (existence of the) canonical answer is not obvious. If OP had been subjected to "what have you tried?" treatment, and actually been able to come up with something, that code might very well have been a manual for loop rather than using the built-in method intended precisely to prevent code from containing such. And if OP did post the loop up front, "is there a more elegant way to do this?" might well be deemed subjective or codereview.SE material. Commented Jul 28, 2022 at 17:57
  • 2
    This situation is incredibly common, in fact I'd wager a majority of the highest voted canonicals don't ask the question that matches the answers at all. Even the highest voted answer on SO doesn't actually relate at all to the question it's been posted under. Commented Jul 29, 2022 at 6:40
  • 1
    Not actually reading the question (only scanning for keywords) or misinterpreting it is common. Another example. Commented Jul 29, 2022 at 13:31
  • 3
    Questions are important for the site because they organize the site contents. Reading the question is supposed to confirm that what's being answered matches what you had in mind, because typing several paragraphs into the search box isn't feasible. Commented Jul 29, 2022 at 16:44
  • 2
    @PeterMortensen I am personally guilty of such misinterpretation on many occasions, I am sure. Commented Jul 30, 2022 at 3:36

7 Answers 7

11

Generally: if an answer addresses some question that is somewhat related to the original question, but isn't useful for people who are looking for an answer to the original question, then just downvote it. (In case anyone doesn't know, this meta post explains why the "Not An Answer" flag should not be used for answers like these.)

In this specific case, though, I believe that solutions using Counter are likely to be useful to many people searching for a solution to the original question, because people may actually want to count occurrences of all elements and think that it is easier to search for how to count occurrences of just one element (i.e. an XY problem). So personally I would not downvote an answer to this question just because it doesn't exactly answer the original question. The most highly-upvoted answer covers both cases without too much text, which seems fine to me.

Other than that, I note that you added a comment directing dupe-closers to the other question; I added another one directing searchers there, too. Ideally, that other question should also appear at the top of the "related questions" list in the side-bar, though I don't know how the algorithm for deciding that works.

21
  • 9
    I'm somewhat skeptical of the ability of downvotes to counter the long tail of crap on questions like these Commented Jul 28, 2022 at 14:59
  • No, you should not post answers to your presumed question. If the question is ambiguous and you answer it, then it's your fault for not clarifying when you answer is deleted. If the question is not ambiguous but you misinterpreted the question, again your fault. If you decide to ignore the question and answer whatever, it's also your fault when the answer is deleted. And they should be deleted. Future readers should not, must not, waste their time reading stuff that they didn't want.
    – Braiam
    Commented Jul 28, 2022 at 15:39
  • 1
    @Braiam I'm not sure who you're addressing with that comment; we're talking about a question which is not ambiguous, but which has existing answers which address a related question, and what should be done about such answers. And I didn't say anyone should write more answers.
    – kaya3
    Commented Jul 28, 2022 at 16:55
  • 1
    Ah - I didn't only mean what to do about the bifurcated answers, but what to do about already-existing duplicates. I think they should be rerouted, but it would require manual verification and there is a lot of work. Commented Jul 28, 2022 at 16:57
  • 1
    @kaya3 if you continue reading, you will notice that it's not only ambiguous questions, but detailing all the invalid arguments that people can spew about not answering the question asked, up to and including your own argument. Just because there's a "related question", doesn't mean that I can answer it in another question. It's a nightmare to find useful stuff. If you think about a related problem for which you have an answer ask another question and answer that.
    – Braiam
    Commented Jul 28, 2022 at 17:02
  • @KarlKnechtel Do you mean what to do about lots of other questions which have been closed as a dupe of this one but should really be a dupe of the other one? That sounds like more effort than it's worth, and I'd question the value of keeping so many dupe-signposts around anyway.
    – kaya3
    Commented Jul 28, 2022 at 17:07
  • 1
    @Braiam We're specifically talking about questions which are not ambiguous. It's right there in the title: what to do when the question is fine but.... It looks like there is something else you want to rant about, but it is unrelated to the discussion we're having here. Anyway, posting a new question is a bad idea because it would be a duplicate.
    – kaya3
    Commented Jul 28, 2022 at 17:10
  • 2
    I mean exactly that. As for the value of it, many of those questions can't easily be deleted. Also, to my understanding, the site relies on number of the count of such links (among other factors) for search optimization (you can even sort results by that value). Part of the reason I'm asking the question is to point out just how much technical debt the site has, and also extract some general principles. Commented Jul 28, 2022 at 17:10
  • 1
    @kaya3 I think what Braiam is say is pretty clear and I don't understand why there is difficulty understanding it. The point is indeed about the answers, not the questions. The argument is that the answerers are clearly in the wrong: the "relatedness" of the OP does not justify them in answering a separate question simply because they thought OP's question was too easy. One of those answerers should have asked and then answered the harder question back in 2010, in this view. Commented Jul 28, 2022 at 17:12
  • @kaya3 "If the question is ambiguous [...] If the question is not ambiguous but you misinterpreted the question, [...] If you decide to ignore the question and answer whatever, [...] [any of such answers] should be deleted" If you read past the first sentence you will notice that I literally put 3 cases, two of which are the ones you argue about and all of them should be dealt the same way: deleting those answers.
    – Braiam
    Commented Jul 28, 2022 at 17:17
  • 2
    @Braiam I'm aware that you have a cavalier attitude towards deleting content which other users consider to be very helpful, because you have made that clear in a previous comment thread under one of my other meta.SO posts; and your position on that has not become popular since then. Your comment "No, you should not post another answer" is out of place here because nobody has advocated for posting another answer, and your advice seems to be targeted at a hypothetical person who was writing an answer 12 years ago, not anybody involved in this discussion today.
    – kaya3
    Commented Jul 28, 2022 at 17:24
  • 1
    @Braiam "I really don't care if you move the content or delete it". The content has 2000+ upvotes, and you say you don't care if it is deleted; that is called a cavalier attitude, sir.
    – kaya3
    Commented Jul 28, 2022 at 17:39
  • 1
    In fact the answer with a score of 2270 has only one downvote in 11 years, so it is reasonable to suppose that a lot of people found this answer useful despite searching for the different question, and very few people considered this answer to be a waste of their time; so the thing you are concerned about here (people's time being wasted) does not seem to be happening, and the thing I'm concerned about (people finding answers that are useful to them) does seem to be happening, a lot. Now if you don't like wasting people's time, I suggest finding someone else to vent your frustrations at.
    – kaya3
    Commented Jul 28, 2022 at 17:51
  • 3
    Of course they would find it "useful" since they are directed from these kinds of questions that ask for those answers. Also, 1 downvote? Are you ignoring that the vast majority of users don't have accounts? It has received 216 downvotes.
    – Braiam
    Commented Jul 28, 2022 at 18:23
  • 2
    @Braiam " since they are directed from these kinds of questions" I think that one might actually be a better canonical than stackoverflow.com/questions/2161752. It asks for output in a sensible format, didn't confuse answerers by showing sorted data and insisting that it isn't ordered; and the top voted answer shows collections.Counter. Commented Jul 29, 2022 at 1:41
3

My assessment of consensus

  • Nothing really needs to be done about answers to How do I count the occurrences of a list item? (hereafter "Original"), aside from letting the votes decide.

  • How to count the frequency of the elements in an unordered list? (hereafter "Candidate A") is not actually a good canonical for the "count all things that appear" question, despite the effort I've put into improving it. h/t @metatoaster for finding this one.

  • Using a dictionary to count the items in a list (hereafter "Candidate B") is much better: it does not have a conflicted history, is easy to understand (with a sensible desired output format), and basically has all (and only) the answers one would want it to have. h/t @Braiam for finding this one.

  • Neither Candidate A nor Candidate B is really a duplicate of Original, despite that Original offers answers for that problem. People who have the question of Candidate B could easily find Original, and might plausibly even have searched with something like Original in mind.

Action taken

Candidate B was previously marked as a duplicate of Original; I unmarked it, and added a "see also" type note. Before Candidate B was uncovered, @Peter Cordes added a "See Also" note to Original pointing at Candidate A. I edited that to point to Candidate B instead. I closed Candidate A as a duplicate of Candidate B. At some point in the future, I will put some effort into redirecting duplicate closures to Candidate B where appropriate.

2

Let me rephrase the conflicting question a bit:

Original
how do I count how many times a given value appears in a list?
Modified
how do I count how many times a given value appears in a list in a loop?

That is actually a pretty natural relation. When someone asks "How to do X for each element?", then it is common to see the comments nudge them towards "Well, how to do X for one element?" – or even outright duplicate closure. In many cases, "X for each" and "X for one" are the exact same issue.

Critically, I would expect someone trying to solve "X for each" to search for "X for one".

As a result, it is completely fine for an answer to cover the modified question as well. In fact, in my book it is what sets apart an okay answer from a good answer – explaining that there is an optimised solution for a specific, common case. It is exactly the kind of insight an SME can provide when facing a naive question.

There is no need to disentangle the questions.


That said, the original question is not gone just because it might imply a related question. Answers still should cover or at least acknowledge the original question itself – covering the modified question is an extra.

Curate the Q&A as is. Use downvotes when answers are not useful to address the question. Use flags when answers merely duplicate what is there already. Use comments to warn about dangerous or misleading advice.

2
  • 1
    Okay, but what is your assessment about future duplicate closures? For example, should stackoverflow.com/questions/3496518 remain closed as a duplicate? Should it be used to close other things, or do I have to accept that the main question is the canonical for both concerns now? Duplicate-closure "chains" leave a really bad taste in my mouth. Commented Jul 30, 2022 at 20:17
  • @KarlKnechtel I'm somewhat undecided on historically grown things. If it were asked fresh today, then yes I would definitely dupe close it; the dict constraint does not really change the task and there are adequate answers on "how do I count how many times a given value appears in a list?" already. Since it already exists... at a glance it seems not to hold any unique insights, so I would dupe-close but not with extreme prejudice. Commented Aug 1, 2022 at 9:05
2

After writing my first answer on this meta (and editing the linked question), I had some second thoughts.

Adapt this question to cover both things

They’re related enough problems, and the single-item one is trivially answerable (for simple lists at least; I don't think the histogram answers are drowning out valuable stuff about more complex keys). That's important; if there was much to be said beyond using .count(), we'd really want to separate it out from the every-element answers. I don't know Python well, but I gather that there isn't.

Many of the every-element-counting answers on this question look better to me than on other potential canonicals that are specifically about frequency counting / histograms. (At least compared to How to count the frequency of the elements in an unordered list? where the top answer is ok, but without much text, and the next two answers are less efficient ways to do it, one of which is a naive O(n^2) method with over a hundred upvotes. And another that proposes a sort. I expect both of these are much slower than the one-pass O(n) was adding into a dictionary.)

But this more popular single element canonical has some good answers that explain the efficiency consideration, and one with benchmarks for multiple good ways, including some NumPy. Deletion of many of those answers doesn't look like a good option, unless there's another potential canonical with an equally good collection of answers.

So there are good answers; we just need to help people find them, and justify their existence. The question could ask "how to count an element or every element in a list?" (I don't actually like that wording, suggestions welcome.)

If it was being asked new, yes of course we'd want it to be one or the other. But we have all these good answers, and we'd like to have a label to put on them. At this point I think the path that keeps the most good answers in a findable place is to accept the hand we've been dealt by historical sloppiness and keep the answers there as they are, tweaking the question to match.


Ideally, we could get the histogram answers split off to a new Q&A, which this one could link. But until / unless a moderator (or SE staff?) has time to sort through each answer and do that, a combined question is not a disaster.

12
  • 2
    I could have sworn I've been told before that we either shouldn't, or aren't allowed to, modify questions in that sort of way, because of something something authorial intent, something something creative commons license. Would appreciate clarification from a relevant authority. Commented Jul 30, 2022 at 3:34
  • 2
    @KarlKnechtel: Creative Commons explicitly gives permission to make and publish derivative works; that's why we have an edit button. The justification for not editing is a bunch of hand-wringing about not stepping on people's toes. (Often including those who haven't been on Stack Overflow for years and haven't updated their answers as tech changes, or once it turned out they were wrong. That's not the case here, \@weakish has been on in the past week, and there wasn't anything wrong with the old question. But so much the better; if they dislike an edit, they can roll it back.) Commented Jul 30, 2022 at 3:42
  • 2
    @KarlKnechtel The major reason for not changing the scope of questions is to avoid invalidating existing answers. This situation seems to be the exact opposite case - we would be validating existing answers. Commented Jul 30, 2022 at 8:32
  • @MisterMiyagi and still ignore the "intent" of the author? Also, should I start posting off topic answers to question and get my answer validated editing the question? That is ridiculous. It would have been that the question is too broad and I narrow it down to a single issue and answer that, but here we make the question broader just to accommodate people that don't bother to read.
    – Braiam
    Commented Jul 30, 2022 at 11:18
  • @Braiam If your answer is closely enough related to a) still match the gist of the original question itself and b) be accepted by the community via votes, then by all means yes. Many canonicals have been created by generalizing existing questions. Commented Jul 30, 2022 at 11:24
  • @MisterMiyagi one thing is generalizing the question, another is to tack another question just to accommodate off topic answers. I am all for generalizing questions, removing irrelevant details/restrictions. I'm also for narrowing the scope. Note that on both cases we remove information from the question because it's not necessary or obscure the issue, we do not do the opposite.
    – Braiam
    Commented Jul 30, 2022 at 11:29
  • @Braiam Well, we can easily remove the restriction to one item from the question to satisfy that constraint. That seems like a rather arbitrary, technical restriction, though; in the end, adjusting the scope properly seems more beneficial. Commented Jul 30, 2022 at 11:36
  • @MisterMiyagi "adjusting the scope properly seems more beneficial" And what you propose, how it's proper? How what I propose isn't proper? At the end, your argument relies in do what you believe it's best. My argument relies on knowing what it's best: waste the less time for readers to read the questions. All the top answers on that question have downvotes, because they were not what the reader expected to read. Having the same question try to serve both purpose makes both kind of readers waste their time. So it's proper to separate the issues to cater to the requirements of both.
    – Braiam
    Commented Jul 30, 2022 at 13:17
  • There is a way to direct those that do not want one or the other to the appropiate question: link to them on the answer. The comment about Counter added to the top answer to the question could very well link to the other question that wants the frequency table, same thing could be done the other side.
    – Braiam
    Commented Jul 30, 2022 at 13:18
  • 1
    @Braiam "My argument relies on knowing what it's best: waste the less time for readers to read the questions. All the top answers on that question have downvotes, because they were not what the reader expected to read." I applaud your ability to know – and definitely not just believe – what's best and why arbitrary people did things. I'm honestly at a loss as to how to reply to that other than saying "I disagree" before this turns into another of those "but we have a consensus because no one disagreed anymore" situation. Commented Jul 30, 2022 at 13:24
  • I know, and not believe, because I base my decisions on actual data, namely anonymous feedback on post and because SE not only literally asked them, it's the whole purpose of that button (pss, it says so in the tooltip ;)). So, yes, I can know why "arbitrary people did things", because that's why those things are there. Also I know what's best, since at very least, those people didn't found those post useful.
    – Braiam
    Commented Jul 30, 2022 at 16:42
  • 1
    @Braiam Even if we leave aside that there are people who downvote for arbitrary reasons, you still cannot infer what is best from that feedback – you only know what is not best. The direct meaning of downvotes is merely "not useful" – that might be because it misses the question, because it lacks explanation, because it is inefficient, because it is low-effort, or many other reasons. That a significant number of people downvoted because answers were addressing both topics is pure speculation. Commented Aug 1, 2022 at 9:24
0

For now, edit the question itself to mention the XY / related problem and link a canonical for that

As a first step in sorting this out, let’s decide that this question should be about the single-key .count() case. That's what the top answer starts with, and presumably there are lots of links to it for that reason.

This question presumably comes up high in search results for the related problem of histogramming. It sounds similar, but it should be solved differently (repeated use of .count() is horribly inefficient; this is what dictionary data structures are for.) Some answerers probably wanted to stop beginners from making that mistake by pointing out that there's a different way to histogram. (As well as some maybe not realizing.)

To avoid the need for answers to cover that, the canonical Q&A itself can point out the existence of the related problem, and direct future readers to a canonical Q&A about that (also helpful for those searching for duplicates). Comments under the question can do that, but I propose that the actual text of the question should include a footnote.

I actually made an edit to do that. It came out significantly longer than the original question, making it visually distracting. To mitigate that and make it visually clearer that it's a footnote, I put it in <sub> formatting, like so:

Given a single item, how do I count occurrences of it in a list, in Python?


A related but different problem is counting occurrences of each different element in a collection, getting a dictionary or list as a histogram result instead of a single integer. For that, see other questions such as How to count the frequency of the elements in an unordered list?

(I quote it here in case further edits change it, e.g. if it's unpopular with the community to put XY guidance in the very question of simple canonicals.)

My edit also added the word single to the original sentence, further focusing it on counting a single key. I decided not to complicate the wording by emphasizing that it might appear 0 times (not necessarily an element from the list), or that it should return an integer. I did sneak the latter point into my XY-problem footnote.


It would probably be good for there to be some mention of the existence of the histogram answers on that question using collections.Counter and other methods, despite the question now saying it's not about that. But that would be too much clutter for a footnote, especially for such a short question. It is best left for comments. I added a more verbose comment than the existing one linking this meta.

3
  • 1
    Makes no sense. You meta folks for some reason never understand that SO is a minor partner here, to Google. Whatever your petty fuss with editing the question won't stop the giant to send people there. Your other answer, on the other hand, is a spot on. Given we are lurking here not only to get our beloved badges, but also to provide some useful information for visitors from Google as a side effect, providing answers for both questions is the right thing to do. It should be the answer though, not question. Nobody cares for what is written in question Commented Jul 30, 2022 at 7:31
  • @YourCommonSense: I never imagined or suggested that just editing the question would stop people from ending up there when searching. The goal was just to point future duplicates at more appropriate targets, and head off further "off topic" answers. As a minimal first step without doing anything drastic or major, let alone stupidly destructive like Braiam likes to suggest with deleting useful answers. Commented Jul 30, 2022 at 8:06
  • @YourCommonSense we provide the answer to both questions, in two separated questions already. The problem is that some people took a cavalier attitude with what one of the question asked and proceed to post their off topic answers there.
    – Braiam
    Commented Jul 30, 2022 at 11:13
-3

That kind of questions should just move the off-topic answer to another question. That way those that want to know the count of a single element get exactly that, while those that want a frequency table of all elements also get that.

11
  • 3
    While I agree in principle, I suspect that nobody is willing to do this. It won't be possible in most cases to ask the original authors; others copying the answers across would potentially be plagiarizing; and mods are typically not SMEs. The answers would typically also need to be adapted to the context of the new question, since people often write answers based on the exact code shown in OP rather than making a fresh example. Commented Jul 29, 2022 at 1:43
  • @KarlKnechtel here's the thing, you do not need the authors to do anything. SE has tools to move answers around. Also, we don't actually need to move answers, since there are questions that already have the answers we want. We have two questions, both of them have desirable answers, one of them have undesired one. Just remove it.
    – Braiam
    Commented Jul 29, 2022 at 10:49
  • 3
    There seems to be little point to moving answers. Q&A(s) for the other topic already exist; transplanting the wrongly posted answers will only clash with existing answers on the other question(s). Commented Jul 29, 2022 at 13:32
  • 2
    @MisterMiyagi there is less point to keep them where they are. Also, there is yet another option: removal. If the content is redundant, removing it is the way to go.
    – Braiam
    Commented Jul 29, 2022 at 23:09
  • Unfortunately the content isn't redundant; there are some high-quality answers about histogramming on the question that's nominally about single-element counting. e.g. some about NumPy, and the algorithmic slowness of repeated .count() vs. an O(n) answer. The best canonical people have found so far has answers that are significantly less good, IMO, looking at the top few answers by trending sort. Commented Jul 30, 2022 at 3:11
  • @PeterCordes well, then there is a point to move those answers. Either way, there is a solution to be that doesn't imply keeping the answers in the wrong place. Just decide which is it and do it.
    – Braiam
    Commented Jul 30, 2022 at 11:11
  • @PeterCordes "The best canonical people have found so far has answers that are significantly less good, IMO, looking at the top few answers by trending sort." Would appreciate some insight into what you find lacking in those answers. I would be happy to try to improve questions such as stackoverflow.com/questions/3496518. Commented Jul 30, 2022 at 20:20
  • @KarlKnechtel: I had mostly been looking at How to count the frequency of the elements in an unordered list?, not the one you linked. On that one, the code on those answers is fine, but there's no text explaining why they're good (for efficiency). And there's no NumPy answer on that question. And the 3rd answer is an O(n^2) example of how not to do it. Commented Jul 30, 2022 at 20:29
  • I think the O(n^2) answer is fine to have, since it's usable; it's commented explaining the performance issue; and it's what one would naturally write if one already knew about .count. I don't think that the lack of a Numpy answer is a huge issue, but I'm certainly not opposed to adding one - I did unmark it as a duplicate partly to allow for that sort of thing. I'm pretty well set on using it as the canonical unless someone finds something better, because the question is quite well asked and the top two answers are good quality. Commented Jul 30, 2022 at 21:15
  • Oddly enough, the Numpy approaches (using either .bincount or .unique) are more suited to the ugly stackoverflow.com/q/2161752 question, as they directly give something much more like that weird desired output format. Commented Jul 30, 2022 at 21:19
  • I went ahead and added a Numpy answer. Commented Jul 30, 2022 at 21:40
-3

The answer really depends on how one understands the purpose of this site. It seems that the majority understands it as following some petty regulations to the letter. From this point of view, the question must be marked as off topic and got ridden of. Or some pointless action such as "vote and move on", "write a 64th answer and move on" should be taken.

For ones, who understand the noble purpose of this site as to provide good answers for millions coming from Google, the answer is different. That is, to make the answer useful and the information easy to find out.

Which means it's the answer has to be edited, not question. Come on, nobody cares for your questions other than Google. When you're coming from Google, you just skim over the question straight to the answer. It's the answer that must be edited, not question.

There are two kinds of questions, regular and popular ones. Unfortunately, almost no one understands the enormous difference between these two kinds, and always judges the latter by the petty standards of the former.

To me, popular questions are a completely different kind. Such petty concerns as as the ego of some person who managed to be the fastest gun in the west 10 years ago, or some regulation inscribed on Tablets of Stone defining this question as off topic, shouldn't be taken into account anymore. That's now a public domain. Therefore, the most popular answer can be and must be edited.

By means of some strange whim, Google decided this question to be the canonical one. Now it means you can't beat 'em. And all you can do is to join 'em. You can't really fight Google, at least as long as Stack Overflow will continue to neglect the basic SEO rules. So this question will attract millions of visitors, not matter what your Stack Overflow regulations say about it.

And it's perfectly possible that a question could have two different answers. This is fine. Our duty is to provide answers for both. Just clarify it at the very beginning, then provide both answers.

If you look from the visitor's point of view, that would be the best solution: the top answer contains the clarification and then one can choose the answer they needed. The main point - all this can be easily found, without browsing through dozens incomplete and too localized answers without reading some fine print telling one to go read another question, without stumbling upon some bureaucratic barriers.

4
  • 2
    I'm not sure what this is supposed to mean in practice. The answers this is about don't answer the question but a different one. How should those be edited? What should be clarified? Commented Jul 30, 2022 at 8:22
  • It has to clarify that "It is possible that you came here looking for answer to either "how do I count how many times a given value appears in a list?" or "how can I count the number of times that each element that appears in the list, appears?"". Again. It doesn't matter what was asked initially ten years ago. It only matters, what answers people are looking for Commented Jul 30, 2022 at 8:26
  • 1
    The top answer already does provide both, and mentions the difference. (Several of the other popular ones do, to). Are you talking about a hypothetical different case of another popular question where the top answer(s) didn't cover both related questions? (I very much agree with your point that popular canonical Q&As should be maintained by the community for the benefit of everyone, regardless of who originally asked it and what kind of shape the question was in originally. Once the question takes on a life of its own, maintain it yourself or expect others to edit your post.) Commented Jul 30, 2022 at 9:06
  • 1
    I do care for the question since that's what I see before clicking from Google. The title and excerpt that Google (and other search engines) show, which comes from the question. I don't skim the question, I literally have already read enough from before clicking. If my decision fails to fulfill my goals and I have to read more answers than necessary (the ideal is that there's only 1 answer), then I would have been bamboozled by the question or the answer.
    – Braiam
    Commented Jul 30, 2022 at 11:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .