Some "pythonic" suggestions for Python

Scott David Daniels Scott.Daniels at Acm.Org
Thu Nov 8 23:17:54 EST 2007


Frank Samuelson wrote:
> I love Python, and it is one of my 2 favorite
> languages.  I would suggest that Python steal some
> aspects of the S language.

I generally agree with the various naye-sayers, but find one
argument missing:

> -------------------------------------------------------
> 2. Allow sequences to be indices:
>  >>> s=["hello", 6, 33, "none"]
>  >>> x= [1,3]
>  >>> [ s[y] for y in x]     # Current verbose version
> [6, 'none']
>  >>> s[x]                   # Simpler, clearer, more productive
> 
> To quote a poster at http://www.thescripts.com/forum/thread22741.html,
> "While we are at it, I also don't understand why sequences can't be
> used as indices. Why not, say, l[[2,3]] or l[(2, 3)]? Why a special
> slice concept? "  Isn't that unpythonic?

Right now, after:

     which_corner = {}
     corner = {}
     for n, position in enumerate([(1,1), (1,5), (3,5), (3,1)]):
         corner[n] = position
         which_corner[position] = n

     which_corner[1,5] returns 1

I would hate to have to know whether which_corner is a dictionary
or a list before I can decide whether this is iteration.

-Scott David Daniels
Scott,Daniels at Acm.org



More information about the Python-list mailing list