[Tutor] a quetion on"There should be one and preferabley one obvious way to do it"

Paul Sidorsky paulsid@shaw.ca
Mon, 21 Jan 2002 01:50:47 -0700


Karthik Gurumurthy wrote:

> So here too we have different ways of getting something done.
> I guess i have not been able to get a clear picture of this python
> philosophy.
> any inputs?

The features mentioned were all added to later versions of Python. 
zip() and list comprehensions were new for 2.0, key in dict is brand new
for 2.2.  This is far from my area of expertise, but from what I
understand they are generally there to clean up some of the uglier parts
of the language.

List comprehensions replace a lot of map(lambda...) garbage which is
very unsightly.

I believe zip() is supposed to fill the gap for where list
comprehensions aren't quite enough by providing a slightly cleaner call
than map().

key in dict is natural to write and is a mistake that just about every
newbie makes anyhow.  :-)

Remember one goal of Python's design is to encourage programmers to
create cleaner code.  These features seem to do that, in my book at
least.

Lastly, if you really want to learn more about the thinking behind some
of these additions then I suggest reading the PEPs behind some of these
enhancements:

http://www.python.org/peps/

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/