8

I was watching and saw this post (revision referenced in this meta post), titled "Complex dictionary construction" (there are many similarly structured questions about regex and list comprehensions, this post is only an example). The question seems like it has some effort put into it:

  • It shows what they've tried
  • It shows the desired input and output

However, the title and body don't contain any actual description, in words, of what the asker is trying to do. My assumption would be that these posts aren't of any value, as I would think they could not be easily searched by other people.

Is this correct, and would I be right to try to close these sorts of posts (with Needs Details or Clarity?), or is no action necessary?

4
  • 3
    I agree with your assessment and can't really think of any more to say about it. Commented Jun 14, 2022 at 21:30
  • 9
    Edit it, leave a comment, and/or vote on it's quality/usefulness. Lack of a good title doesn't necessarily indicate the question is close worthy as unclear or needs details, especially if it has those details in the question itself.
    – Kevin B
    Commented Jun 14, 2022 at 21:32
  • 8
    This question is fine. It could be improved in terms of explicitness, for sure, but any difficulty in understanding what they want is perhaps an issue with mastery of English, not an issue of them not telling us what they want. I have edited it to satisfy your concerns.
    – TylerH
    Commented Jun 15, 2022 at 13:53
  • 1
    This YY problem. Their title is their Y and their body is their other Y.
    – Braiam
    Commented Jun 17, 2022 at 17:25

5 Answers 5

24

If it is clear what the author is asking about or if there is any indication as to what they want to achieve then edit the question and provide the necessary explanation yourself.

If you can't confidently say what the asker is asking about then the question is unanswerable and should be closed. This is most often the case with questions that contain any written explanation.

12
  • 2
    To me, as someone who is currently viewing the post, it is clear to me what the question is asking about. The sample input is there, and the output is as well. However, I was struggling to see how this would be useful to anyone searching for this same problem in the future, as there isn't a specific written description of what they're trying to do. This is why I am unsure of whether I should flag it (or other like questions). Commented Jun 14, 2022 at 21:44
  • 7
    @TheFungusAmongUs This is exactly why you have the privilege to edit stuff (or at least suggest edits). If you can make the question better, whether it's for readability or SEO purpose, then do so. As long as you are improving it while maintaining integrity, everyone will be happy
    – Dharman Mod
    Commented Jun 14, 2022 at 21:45
  • 3
    I'm somewhat uncomfortable with this: It seems to imply (whether on purpose or not) that if you could edit a question into shape one should vote on how the question could look if edited. That puts quite a lot of burden on curators to either invest significant time into a question or leave it in a bad state. IMO that is not the responsibility of people – the OP is responsible for getting the question into shape and other-people-editing is a voluntary action orthogonal to other actions. Commented Jun 15, 2022 at 11:39
  • 7
    @MisterMiyagi Of course the primary responsibility is on the question author, but we are all here not for the points but to make sure that we share useful content with the viewers. If you think the question could be useful after your edit, then do so. If you think that even after your edit the question is unlikely to help anyone else, you can just vote and move on. Our primary goal is to preserve good content.
    – Dharman Mod
    Commented Jun 15, 2022 at 13:27
  • 2
    "If you can't confidently say what the asker is asking about then the question is unanswerable". Oh man, I can close MOST questions with that argument, because I don't have a clue, because I know nothing about the subject.
    – Poul Bak
    Commented Jun 15, 2022 at 17:28
  • 2
    @Dharman Well, most questions I vote "negatively" I could actually edit into shape if only the day had more than 24 hours and my nerve wasn't a finite resource. Point is, neither is the case. Preserving good content isn't the same as preserving potentially good content. Commented Jun 15, 2022 at 18:00
  • 1
    @PoulBak We're assuming a baseline level of subject matter expertise here, yes. After all, it takes some reputation to become able to make edits. Aside from that... don't browse tags for things you don't know anything about? Commented Jun 15, 2022 at 21:08
  • ” It seems to imply (whether on purpose or not) that if you could edit a question into shape one should vote on how the question could look if edited.” @MisterMiyagi I don’t understand how you are inferring this. According to the answer, you would either vote after an edit because the post could be improved or just vote because you’ve decided not to edit it. You are not being asked to vote prior to an edit that doesn’t exist yet.
    – BSMP
    Commented Jun 15, 2022 at 21:48
  • In general, I agree with this response; however, the specific original question has other issues IMO besides a lack of clarity. Commented Jun 15, 2022 at 21:57
  • @KarlKnechtel: When reviewing, you don't get that choice. However I see many questions being closed just because the reader don't understand the question.
    – Poul Bak
    Commented Jun 15, 2022 at 21:59
  • 4
    For a good example of unclear questions like this, look at regex. You'll see input specified (eg "ABX 500") and output specified (eg "500") but without a description you're guessing. (Match "500" literally? Numbers of any length? 3 digit numbers? The last 3 characters? Anything that comes after a space? I could go on...)
    – Laurel
    Commented Jun 15, 2022 at 23:48
  • @BSMP Because the answer only has two categories: just enough details to edit and thus should be edited, or too little and thus close worthy. There is a third case: just enough to edit but no one makes that edit. Commented Jun 16, 2022 at 7:11
10

I would have voted to close as needs more focus. The fact that OP wanted to title it "Complex dictionary construction" originally, indicates the problem. There are several steps that need to be taken in order to do what is asked.

  1. Given the list of lists, isolate the first list (key names) from the others (indices + data). Skip the first element, since we don't need a "name" for what will become the dict keys.
  2. Given an 'index + data' list, separate the index from the data.
  3. Given the key names and data, pair them up and create a dictionary.
  4. Given an index and dict of the sort described above, make a key-value pair; iterate this process for each 'index+data' list, to create the outer dictionary.

Yes, OP made an attempt to write code to solve the problem. But we don't ask "what have you tried" simply as a barrier to keep out help vampires. We ask that because it helps narrow questions and clarify sticking points. The original attempt at writing the code shows competency with writing Python code, but it doesn't demonstrate the above analysis. At best, it shows that 4) is understood, and 1), 2) and 3) are still in question.

Notice that each step of this is a matter of elementary technique, and could itself presumably have been closed as a duplicate:

  1. Use slicing (or unpacking).
  2. Use unpacking (or slicing) again.
  3. Use zip to pair parallel values; the result can be fed directly to dict.
  4. Use a dict comprehension.

The accepted answer shows these off:

keys = spam[0][1:]
#      11111111111
result = {sno:dict(zip(keys, values)) for sno, *values in spam[1:]}
#        4222233333333333333333333333 444 222222222222 44 111111114

I admit my selection of a duplicate for 2) is a bit weak, but I assure you that experienced Pythonistas do this sort of thing all the time, to the point where it's just one of those idioms that people know. (It probably should have a better duplicate, specific to the context of comprehension. This is an important technique because slicing is awkward here; we don't have real let-expressions and the walrus operator doesn't work like you might expect.)

( 3) was obnoxiously hard to find; even [python] dict lists of keys and values does not turn it up in search; you have to write dictionary in full, even though that query does turn up much less relevant answers that say dictionaries.)

My point is, the combination does not make a good question. I would have been tempted to dupe-hammer it with all four links above, although I'm sure that would be frowned upon. But a question like this is essentially treating Stack Overflow as the code-writing service that it isn't; OP has a task to make the code perform, not a specific problem arising from doing the expected research and problem decomposition and still hitting a sticking point in the code.

ETA: looking at comments on the question, I only solidify my impression that this is being presented as a code-writing request. There's a follow-up comment from OP: simply "how do I it if i want age to be the primary key". This doesn't show a proper understanding of how the given solution works, OP figured out how to modify the keys, but not the values (because they are no longer contiguous, the unpacking approach will no longer be particularly neat). The code in the answer would be more understandable if a) split up into functions and b) appropriately commented - but adding this detail only serves to emphasize the lack of focus.

5
  • 2
    My 2cts: Yep, you are completely right (in "Theory"), but you (and al Answers and Comments here on Meta) only focus on the (original) Qt itself and the @OP... Don't you think that the 4 (or 3 now) FGITW Answerers (who apparently didn't have any Pb understanding the Qt as they all posted within 10 min) also have a "Responsibility" for the overall Quality of the Thread...? The Qt has now been edited quite nicely/usefully (Title + Body), but all Answers were just "Try this: + Output:", => oh, perfect...!, one got 65 Rep-Pts in 3h, now up to the next easy Qt... Funny Game...!
    – chivracq
    Commented Jun 15, 2022 at 22:42
  • 4
    Yes, they have a responsibility as well. However, I can't see the problem being fixed any time soon - not with the site design being what it is. Commented Jun 15, 2022 at 22:55
  • 2
    Yep, neither do I (... see the problem being fixed any time soon ...), as there is no Rep to be gained from finding a Dupe and closing a Qt, + no Penalty for answering such Qt's, + even if/when the Qt gets closed, Answers posted before the Close remain and will still garner more (Up)votes, especially if/as the Qt itself gets improved and will probably act as an even better Sign-post to attract "Traffic" to that Thread/Qt... and its Answer(s)...
    – chivracq
    Commented Jun 15, 2022 at 23:11
  • ... Possible Solution: 5k(+)/10k(+)(?) Users prevented to post an Answer within the 1st hour, (they will at least have the time to "prepare" a "better" Answer than just "Try this: + Output:") + (Temp) Answer-Ban after 5 (or 10?) Answers (within 1 week?) to Qt's that get closed as Duplicates within 24h after they (were) posted. + No Rep gained anymore after the Close. [+ Maybe some Rep to be gained from finding an ("accepted") Dupe (+ VTC), although I'm not sure that's a "good" Incentive...] ... Just an Idea...
    – chivracq
    Commented Jun 15, 2022 at 23:40
  • The ever elusive YY problem. Where the actual underlying problem is missing :)
    – Braiam
    Commented Jun 17, 2022 at 17:29
3

but not in writing?

Clear problem statement in prose that's not just code is a must!

What the author in the referenced example question is asking about is how to convert a list of lists into a dictionary of dictionaries... It can be summed up in 1 sentence, and there's sure to be an endless amount of duplicates already.

In the example I'd leave the keyword sentence in the comments and go find a duplicate target.

1
  • 3
    This. Even if the keywords aren't perfect, they are much better than nothing. A lot of people search with imperfect keywords, so using "simple" language can actually be a good thing. Commented Jun 16, 2022 at 8:32
3

The problem is not only that questions that only show the desired inputs and outputs as code examples are not good signposts, the problem is also that examples can only ever show what the code should do for those specific examples. Examples can never be general rules.

For example: in the example in the question, the OP shows the Sno value becoming the outer key of the resulting dictionary-of-dictionaries, and further shows the key value being unique. However, in a comment, the OP indicated that the key can be variable, i.e. that the key is not always Sno (in the comment, the OP mentions age), and that the key could have duplicate values (ages are not necessarily unique).

This requires a completely different kind of solution; in fact, it means that the OP's desired output is actually impossible to achieve in general! However, there is absolutely no way to figure this out from the single example input and output provided.

Here is another example from the Ruby tag. The OP wants to sort an array-of-hashes (list-of-dictionaries in Python terms) which contains an id key based on the order of IDs specified in a separate array. Not all IDs need to be present in that array, and for IDs that are missing from the array, the only thing the OP specifies is that they "just don't need to sort them and let them be as they were."

However, in the provided example input and output, it just so happens that all the IDs which are not specified in the ordering array happen to be at the end of the array-of-hashes in both the input and the output and they happen to be in ascending order in both the input and the output. It also happens to be the case that all IDs specified in the ordering array are present in the input, and it happens to be the case that the keys are unique. It is absolutely not clear from the provided example which of those facts are coincidences, and which of those can be relied upon to always be the case.

It is unclear what guarantees can be assumed of the input (are the keys unique, are the missing keys always at the end, are they always in ascending order, are they always greater than the keys which are present in the ordering array) and what the requirements are for the output (do the missing keys need to be sorted).

It required several hours of back and forth to clarify that, in fact, all the OP needs is to have the missing keys at the end of the array in an arbitrary order. It is still not clear whether it can be assumed that the keys are unique, for example.

Note that there are two different answers, each of which have inferred different rules from the single provided example, and neither of which are actually correct according to comments by the OP.

Ideally, such a data structure transformation question should include:

  • A specification of the rules for transforming the input into the output, including not just the "normal" ("happy") case but also any and all special cases, edge cases, corner cases, boundary cases, and exceptional cases. (Classic examples: no input, empty input, singleton input, duplicate keys, duplicate values, missing keys, missing values, irregular input shapes, …)
  • A specification of the possible valid inputs.
  • A specification for the possible valid outputs.
  • Examples of input / output pairs demonstrating both the normal case as well as the special cases, edge cases, corner cases, boundary cases, and exceptional cases.
  • A skeleton API for how the data transformation code is to be used.
  • Ideally, the input / output examples should come in form of a test suite using the skeleton API. That way, all an answerer needs to do is fill out the missing bits of the skeleton API and run the test suite to know whether the answer is correct.

The human-readable specification serves as fodder for the search engine, the test suite makes it easy for answerers to check the correctness of the answer. In addition, having two separate specifications (in words and in code) serves as a form of sanity check akin to double-entry bookkeeping.

1
  • 4
    This. A million times. Some sample input & output is better than none, but it is often the case that the input supplied by newbie OPs is inadequate and often misleading, especially when there's no accompanying text that attempts to explain the actual data processing task that the code's supposed to perform.
    – PM 2Ring
    Commented Jun 16, 2022 at 18:58
1

Not only was this asked before, there's a dupe for it. It should be closed as a dupe.

The OP wants to convert a list of lists into a dictionary. That's it. That's all there is to it.

Python questions tend to have an expression problem; it is tough for someone in Python to say exactly what they want, so it's tough for them to search for it. This is where you come in - because you do understand what the OP is looking for, you should help them get to that point of understanding.

I do want to call attention to this sentiment:

However, the title and body don't contain any actual description, in words, of what the asker is trying to do. My assumption would be that these posts aren't of any value, as I would think they could not be easily searched by other people.

Yes, but...well, yes.

I hesitate because of the aforementioned "expression" problem above. If someone doesn't know how to say something, then closing their question doesn't help them say it any better. In the best case scenario, there's already a dupe that you can point them to. In the worst case, you'll need to close the question to compel the OP to tease out what it is they're actually looking for.

40
  • 2
    Yep exactly, the Qt (on SO-Main) looks to me like a perfect example of FGITW with 4 Answers posted within 10 min, mostly by High-Rep Users in the Tag, one User removed their Answer or didn't hit the 'Submit' Button when they realized they got "beaten" by a few seconds, and all those Users preferred to try to answer the Qt as quickly as possible, instead of checking for a Dupe...
    – chivracq
    Commented Jun 14, 2022 at 22:21
  • 2
    This is exactly what I have been thinking and saying lately. One of the hardest things is to name the problem you are having, yet alone search it. On the flip side I think that merely knowing what your problems are called makes you a great programmer, so there is a clear relation here. To learn the aforementioned, you sometimes need to ask stupid questions and sometimes the only way to ask is to... not ask, but instead rely on someone hopefully catching on as you try to describe and explain it the hard way. 1/2
    – Swiffy
    Commented Jun 14, 2022 at 22:26
  • 2
    Then there are the non-native English speakers as well. Formulating the question is not the only hard thing for them - a great deal of resources, documentation, etc. regarding programming is in English, which often makes it tough to come up with answers, or even if you do, you might not understand them perfectly, so you'll have to ask using the best english you are able to write. 2/2
    – Swiffy
    Commented Jun 14, 2022 at 22:30
  • 5
    I don't disagree that there may be a dupe and if there is this should be closed for that reason. But that dupe target does not result in the expected structure. Specifically it doesn't explain or demonstrate how to use the first column of the 2d list as the top level key of the new nested dictionary structure. It also does not create or explain how to create a dictionary for reach row keyed with the header (excluding the first column).
    – Henry Ecker Mod
    Commented Jun 14, 2022 at 23:17
  • 4
    @Swiffy It can be hard to describe a problem/goal, but that is not a good reason for not trying or doing it. People do not even try. And often they do not know to try. And because they haven't tried, they haven't been able to reasonably research either. Moreover they don't compose [mre]s by which they could pin down problems/goals. I strongly disagree with "sometimes the only way to ask is to... not ask". Posts should be downvoted & closed & posters told "use your words" & told to read & act on the help center.
    – philipxy
    Commented Jun 14, 2022 at 23:55
  • 9
    I'm sorry, but no. "convert a list of lists into a dictionary of some description" is not one size fits all task. Python is extremely flexible with its structures. This allows dictionaries to take a lot of different shapes (literally). This is a very specific type of transformation that is predicated on a number of requirements which are outlined in the question. It's usefulness remains to be seen. It might be so specific that it only ever benefits the OP, the problem might not be clearly defined, but these are different problems than it having been asked before.
    – Henry Ecker Mod
    Commented Jun 15, 2022 at 2:57
  • 5
    I disagree wholeheartedly with closing a question as a duplicate of another which does not: answer the question asked, nor provide a solution that can be easily extended to fit this case, nor explain or elaborate on some shared underlying cause or approach. Yes it is true that most questions have been asked before, but if we can't find a target for this one than maybe it is a novel transformation (in base python I did find a similar transformation in pandas/numpy) or minimally a type of question that needs better signposts.
    – Henry Ecker Mod
    Commented Jun 15, 2022 at 2:57
  • 2
    That target duplicate does not reflect the problem OP has or the output they desire. It would be a bad duplicate closure.
    – TylerH
    Commented Jun 15, 2022 at 13:59
  • 4
    @TylerH: Then go find another; like I said, Google's search let me down and Stack Overflow's search is pretty abysmal in this situation. Ultimately, there aren't any new or novel data transformations in Python, just pages and pages of similar ones.
    – Makoto
    Commented Jun 15, 2022 at 14:40
  • 5
    @Makoto It's not my job to find a duplicate to back up your claim that it's a duplicate. If you think it's a duplicate, it's your responsibility to find one.
    – TylerH
    Commented Jun 15, 2022 at 15:07
  • 3
    @Makoto As of the last time I checked (which is just now) the duplicate recommendation comment of yours is still there. It's great that you agree it is wrong, but if so why is the comment still there? Why is this answer still suggesting that that's a duplicate? I don't see what is "derisive" about posting my disagreement with your still-current argument.
    – TylerH
    Commented Jun 15, 2022 at 15:25
  • 2
    I also don't see how it logically follows that it's my responsibility to find a better one just because I think the one you offered is wrong. I am not saying "this is a bad duplicate target, there are better ones out there"... just "this is a bad duplicate target". For the record, you actually can post as many comments as you want. It is a fairly common occurrence for users to suggest additional/better duplicates in the comments after OP says the first one is not correct.
    – TylerH
    Commented Jun 15, 2022 at 15:26
  • 5
    I feel like this entire "there is likely a duplicate but we cannot effectively search for it" just underlines that a description in prose is absolutely vital for a question to be useful. Questions without it do in fact lack critical details. Commented Jun 15, 2022 at 15:44
  • 3
    @MisterMiyagi There are a lot of reasons why we can't effectively search for likely-existing duplicates. Including previous failure to close dupes aggressively enough (which would help direct traffic and make a canonical stand out better). Although probably the biggest reason is that almost everyone asking a question wants help with an immediate practical problem, so even in the rare cases where they can construct a reasonably good MRE, it isn't decontextualized in a way that makes it a good dupe target. Commented Jun 15, 2022 at 21:12
  • 2
    @TylerH Because accepting this question in a state that leaves it as a bad dupe target also means that we are likely to have accepted the possibly existing dupe targets in a similar state. How are we supposed to say whether this is a duplicate if we do not ensure that duplicate targets can be found? Being accepting of this "expression problem" as the answer calls it is a serious problem, IMO. Commented Jun 16, 2022 at 16:01

You must log in to answer this question.

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