I don’t have any idea how to be more specific on the problem (how to generate the list of the quarters of the year in the form QQ-YY in Python
This is going to ramble a bit, because the point is nuanced and has some qualifiers.
When a question "Needs More Focus", that doesn't really mean that it needs to be more specific. (That would often fall under "Needs Details or Clarity".) There is enough information to understand what the code needs to do - although it would be better to come up with a specific format for the input (for example, suppose we start with three numbers that tell us the starting quarter, the starting year, and the number of values?).
Instead, a question that "Needs More Focus" is, in most cases, one that combines multiple logical steps. In other words, more analysis is needed in order to ask a question that is about just one thing.
I didn't initially vote to close this question, but as of this answer I have cast such a vote post reopening, with the same reason. In large part, programming is about breaking problems down into smaller steps, and it's possible to carry that pretty far. There is some disagreement over how focused questions really need to be; I personally lean pretty far towards the purist end of this spectrum, because it is useful for establishing good canonical questions.
At the extreme: for a long time, I found questions that I would awkwardly close as duplicates of things like How do I multiply each element in a list by a number? , or Apply function to each element of a list , or Call int() function on every list element? ... the key underlying idea here is "how do I (do something trivial) with each element of a list?", and the point is to illustrate standard techniques: using a list comprehension, an explicit for
loop, or the built-in map
function. The point is that the nature of "do something trivial" isn't that interesting, most of the time - most OPs do seem to know how to do whatever it is they're trying to do, with a single list element.
All of these are really instances of the same problem - but it's hard to disentangle them from the specific "do something trivial" in each individual question. Sometimes new questions come from people who actually don't know how to do the trivial thing for a single element, so they really have two questions. In the older, established questions, while yes it's nice to have an object example to talk about, it draws attention away from the iteration techniques, towards looking for more interesting (, faster, more memory-efficient, ...) ways of doing the trivial thing. There is hardly ever anything about the trivial thing, that actually informs the decision about the iteration technique. It's just a separate issue.
So eventually I ended up writing my own self-answered question for it so I can use that instead - and also talk about how the same iteration techniques can be used for other iterables. The question is abstract, but it's focused on just the iteration technique - not on the per-element task.
In short: when questions are properly broken down, it becomes much easier to identify and make use of duplicates. If you need to know about AB, and someone else needs to know about AC, then having both of you break that down into the separate A, B, C parts means that both of you can be pointed at existing, high-quality Q&A for the A problem, and we don't have to repeat the work. (And then, when you ask your B-only question, that becomes something that can be helpful for the next person who has to do BD.) Also, the isolated A question is easier to explain in terms that make a really good title, which in turn makes it easier to find with a search engine.
Of course, exceptions are made in cases where two tasks are a really common pairing, and/or when there is direct support for doing both tasks at once. e.g. someone who has to read and use JSON in Python doesn't actually need to read the file into an ordinary string as if it were any other text file, and then use the json
library to parse the string; instead, the json
library can be given the open file directly and instructed to parse its contents.
In your case: yes, it's possible to solve the problem with a few lines of code. The question can easily be answered in the scope of a single Stack Overflow answer. And yes, we can understand what the requirements are, at least well enough to fill in the blanks.
However, it's straightforward to see that there are a few obvious logical pieces to the puzzle:
For a given "quarter" string in the output, what should be the numeric year value? (We can figure this out in a variety of ways, but they all boil down to considering the starting point and the position within the output, and doing some math.)
Similarly, what should be the numeric quarter value? (Similarly, we'll just be doing math.)
If we have those numeric values, how do we create the corresponding string? (This is a string formatting task; it isn't clear to me how much you know about doing this sort of thing, but we have existing questions covering that ground - for example, How do I put a variable’s value inside a string (interpolate it into the string)? .)
Given the ability to create an individual string for a quarter label, how do we repeat this process and make a list of the specified number of results? (Oh, would you look at that: I already discussed the existing Q&A for this! :) )
If you didn't already attempt an analysis like that before asking the question, well, that's part of what we're looking for in good questions. (Older answers there miss the point somewhat; we don't really mind duplicating documentation that exists elsewhere, but we want the task to be analyzed so that it can be broken down into useful questions.) If you did, well - where exactly are you stuck?
(If you have a reasonable guess that there should be built-in library functionality for some combination of steps, and just couldn't find it in the documentation, you might try to ask anyway. Don't be too disheartened if it gets closed as Needs More Focus, or with multiple duplicate links. You still learn something this way, right? Please always keep in mind that we close, and vote on, content - not users.)
(If you know that there is under-appreciated library functionality that performs a common set of steps, consider writing a self-answered question to advertise that functionality. Whether something is really "separate steps" can be subjective, too. For example, the standard library's random.choice
could be replaced by checking the length of the input, generating a random number, and indexing in. That's essentially what random.choice
does under the hood, and it's the logical set of steps for solving the problem in languages that aren't as high-level as Python. But clearly in Python, using random.choice
is a much more elegant solution - which is why it was created in the first place.)