Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

For what it's worth, as a dabbling Python programmer myself, I would not have been able to answer the question you linked tothe question you linked to off the top of my head.* Sure, I could've looked it up in the docs or Googled for it — but typically, the most useful Google results for such searches tend to be SO questions just like this!

Not all of those are exact duplicates, but they're all variants of the same basic question, and the all have the same general answer ("use list comprehension"; although there are some rather interesting alternatives buried in some of the answers, like using operator.itemgetter as suggested herehere). Ideally, most of those should probably be closed as duplicates of a single canonical question, possibly this onethis one (first in the list above), but even as they are, they're all still useful sources of information.

*) In Perl, which I'm more familiar with, I'd use what's called a "hash slice" — essentially, indexing the dictionary with a list of keys, and getting a list of values. But while Python also has something called "slicing", it's not really the same thing, so that obvious (to me) approach won't work in Python. That said, Googling for "python dictionary slice" is how I found thisthis dupe, so clearly I'm not the only one with this terminology issue.

For what it's worth, as a dabbling Python programmer myself, I would not have been able to answer the question you linked to off the top of my head.* Sure, I could've looked it up in the docs or Googled for it — but typically, the most useful Google results for such searches tend to be SO questions just like this!

Not all of those are exact duplicates, but they're all variants of the same basic question, and the all have the same general answer ("use list comprehension"; although there are some rather interesting alternatives buried in some of the answers, like using operator.itemgetter as suggested here). Ideally, most of those should probably be closed as duplicates of a single canonical question, possibly this one (first in the list above), but even as they are, they're all still useful sources of information.

*) In Perl, which I'm more familiar with, I'd use what's called a "hash slice" — essentially, indexing the dictionary with a list of keys, and getting a list of values. But while Python also has something called "slicing", it's not really the same thing, so that obvious (to me) approach won't work in Python. That said, Googling for "python dictionary slice" is how I found this dupe, so clearly I'm not the only one with this terminology issue.

For what it's worth, as a dabbling Python programmer myself, I would not have been able to answer the question you linked to off the top of my head.* Sure, I could've looked it up in the docs or Googled for it — but typically, the most useful Google results for such searches tend to be SO questions just like this!

Not all of those are exact duplicates, but they're all variants of the same basic question, and the all have the same general answer ("use list comprehension"; although there are some rather interesting alternatives buried in some of the answers, like using operator.itemgetter as suggested here). Ideally, most of those should probably be closed as duplicates of a single canonical question, possibly this one (first in the list above), but even as they are, they're all still useful sources of information.

*) In Perl, which I'm more familiar with, I'd use what's called a "hash slice" — essentially, indexing the dictionary with a list of keys, and getting a list of values. But while Python also has something called "slicing", it's not really the same thing, so that obvious (to me) approach won't work in Python. That said, Googling for "python dictionary slice" is how I found this dupe, so clearly I'm not the only one with this terminology issue.

Source Link
Ilmari Karonen
  • 50.2k
  • 4
  • 54
  • 86

This is a perfectly valid and useful beginner question. Questions don't have to be hard or esoteric in order to be good — in fact, some of the most popular and highly upvoted questions on SO are also the most trivial, such as:

Questions like these are extremely useful for beginners — and, let's face it, every one of us was a beginner at some point. Indeed, as programming is far from a dying art, the beginners still outnumber the experts by a large margin, and will continue to do so for the foreseeable future.

For what it's worth, as a dabbling Python programmer myself, I would not have been able to answer the question you linked to off the top of my head.* Sure, I could've looked it up in the docs or Googled for it — but typically, the most useful Google results for such searches tend to be SO questions just like this!


That said, new questions like this are quite often duplicates — SO has been around a while, and most of the common, easy and obvious questions have already been asked in some form by now. Just with a bit of Googling, I found:

Not all of those are exact duplicates, but they're all variants of the same basic question, and the all have the same general answer ("use list comprehension"; although there are some rather interesting alternatives buried in some of the answers, like using operator.itemgetter as suggested here). Ideally, most of those should probably be closed as duplicates of a single canonical question, possibly this one (first in the list above), but even as they are, they're all still useful sources of information.

Anyway, it's worth emphasizing that a duplicate question is not a bad question — it just happens to have already been asked before. Sure, maybe the poster of the dupe could've searched a bit more and found the earlier question on their own, but it's also possible that the older question just didn't happen to contain the keywords they were searching for. It's actually a good thing to have such duplicates, since, even if closed, they can serve as signposts to direct other people to the right place to find the answer.

If you come across a new question that looks "so simple that it must surely have been asked before", do try a quick search to see if you can find a good duplicate. (In review, to avoid audit mishaps, do also check that the duplicate you found isn't actually the same question.) Finding duplicates not only keeps SO tidy and focused, but it also helps the asker by quickly pointing them to a bunch of existing answers to their problem.


*) In Perl, which I'm more familiar with, I'd use what's called a "hash slice" — essentially, indexing the dictionary with a list of keys, and getting a list of values. But while Python also has something called "slicing", it's not really the same thing, so that obvious (to me) approach won't work in Python. That said, Googling for "python dictionary slice" is how I found this dupe, so clearly I'm not the only one with this terminology issue.