how to get the ordinal number in list
Roy Smith
roy at panix.com
Sat Aug 9 11:34:22 EDT 2014
In article <338e8fb0-c9ec-462a-b560-1c1ff77de17e at googlegroups.com>,
Rustom Mody <rustompmody at gmail.com> wrote:
> [To the OP]
> Yeah I am in the minority at least out here in considering
> comprehensions simpler than loops. Take your pick
When comprehensions first came out, I stubbornly refused to get my head
around them. Now, I'm totally addicted. To the extent that I consider
dict comprehensions to the THE killer feature of 2.7 :-)
But, putting on my instructor's hat, I think it's important to answer
questions at a level that can be understood by the student. Painting
with a broad brush, there's three or four kinds of people asking
questions on this list:
1) People who are totally new to programming, and are learning Python as
their first language. These are the people who are still struggling to
understand fundamental concepts. They haven't figured out yet that the
first step to solving a problem is to decide what algorithms you're
going to use, and only then can you start translating that into code.
They need to be led in small steps towards basic knowledge.
2) People who are (at least somewhat) experienced programmers, and are
learning Python as a second language. Their experiential background is
limited to one way of doing things (i.e. the Java way, or the PHP way,
or whatever language way they learned first). They mostly should be
shown how translate the things they already know into familiar feeling
constructs. You already know how to write a loop, this is how we do it
in Python. You already know how build a data structure that maps keys
to values, this is how we do it in Python. Only after they've become
comfortable with that, should they start exploring the really cool
features of Python.
3) People who already know many languages, and are learning Python as
their n-th. These folks have seen multiple ways of doing things, and
can understand concepts at a higher level. Oh, Python dicts are more
like C++ STL maps than PHP arrays. Oh, variables have function scope
and don't have to be explicitly declared. Oh, RAII is spelled "with" in
this language. Oh, functions are first-class objects, but code blocks
are not.
4) People who are already proficient Python programmers and are looking
to explore deeper topics.
I think suggesting comprehensions in an answer should be reserved for
people at levels 3 and 4. Maybe level 2-1/2. Certainly not level 1.
More information about the Python-list
mailing list