Teaching : Python, Scheme, Java...

Erik Max Francis max at alcyone.com
Thu Apr 17 04:06:31 EDT 2003


Jean-Paul Roy wrote:

> - Python is bad : tail recursion is not iterative (also astonished at
> that, I can understand with an interpreter, but compiler ?)

I think the reason for this is that there simply hasn't been enough
pressure to do so.  I doubt anyone thinks it would be _bad_, it's just
not enough people have insisted it is worth doing.

> Aside from that points, a personal question as a Schemer who reads the
> Python primer:
> - how do you ask if a list is empty ? Is the following ok ?
>       if L == [] :

Even simpler:

	if L: ...

> - how do you ask if the list has only one element, with time 0(1) ?
> The
>   Scheme/Lisp analog is (null? (cdr L))

I suspect the length of a Python list is cached in the list object, but
don't know that for a fact (a simple test would verify it easily
enough).  I would think that

	if len(L) == 1: ...

would be fine.

> - more generally, is the length of a list a builtin ?

I think so but have not checked.

> Is the L[k]
 access
>   time O(1) with a list ? Probably not. And with a tuple ?

Python lists and tuples are both implemented as computer science
"vectors," so indexing access time is indeed O(1).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Can I walk with you / 'Till the day that my heart stops beating
\__/ India Arie
    Polly Wanna Cracka? / http://www.pollywannacracka.com/
 The Internet resource for interracial relationships.




More information about the Python-list mailing list