Using namedtuples field names for column indices in a list of lists

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jan 10 21:18:49 EST 2017


On Tuesday 10 January 2017 18:14, Deborah Swanson wrote:

> I'm guessing that you (and those who
> see things like you do) might not be used to working with quick learners
> who make mistakes at first but catch up with them real fast, or you're
> very judgemental about people who make mistakes, period. I certainly
> don't care if you want to judge me, you're entitled to your opinion.

Be fair. We're not mind-readers, and we're trying to help you, not attack you.

It is true that we're often extremely pedantic. Sometimes annoyingly so, but on 
the other hand precision is important, especially in technical fields. There's 
a *huge* difference between a MTA and a MUA, even though they differ only by 
one letter and both are related to email.

One of the techs I work with has the same habit of correcting me, and when I'm 
invariably forced to agree that he is technical correct, he replies "technical 
correctness is the best kind of correctness". Annoying as it is to be on the 
receiving end, he is right: at least half the time I learn something from his 
pedantry. (The other half of the time, its a difference that makes no 
difference.)


What are we supposed to do when somebody asks a question based on an obvious 
mistake? Assume that they're a quick learner who has probably already worked 
out their mistake and doesn't need an answer? That would certainly make our 
life easier: we can just ignore everybody's questions.

Sometimes people make errors of terminology that doesn't affect the semantics 
of what they're asking:

    "I have an array [1, 2, 3, 4] and I want to ..."

It's very likely that they have a list and they're merely using a term they're 
familiar with from another language, rather than the array module.

But what are we supposed to make of mistakes that *do* affect the semantics of 
the question:

    "I have a dict of ints {1, 2, 3, 4} and want to sort the values by 
    key so that I get [4, 2, 3, 1], how do I do that?"

How can we answer that without correcting their misuse of terminology and 
asking for clarification of what data structure they *actually* have?

We get questions like this very frequently. How would you answer it?


Or:

    "I have a list l = namedtuple('l', 'field1 field2') and can't 
    extract fields by index, l[0] doesn't work..."

Of course it doesn't work. How would you respond to that if you were in our 
place?

- ignore the question because the poster is ever so smart and will have
  worked it out by now?

- point out that l is not a list, or even a tuple, and of course l[0] 
  doesn't work because l is actually a class?

Its easy to criticise us for answering the questions you ask instead of the 
questions you intended, but we're not mind-readers. We don't know what you're 
thinking, we only know what you communicate to us. Telling us off for answering 
your questions is hardly likely to encourage us to answer them in the future.




-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson



More information about the Python-list mailing list