Python and Lisp : car and cdr

Franck Ditter franck at ditter.org
Fri Jun 17 10:45:38 EDT 2011


Hi, I'm just wondering about the complexity of some Python operations 
to mimic Lisp car and cdr in Python...

def length(L) :
  if not L : return 0
  return 1 + length(L[1:])

Should I think of the slice L[1:] as (cdr L) ? I mean, is the slice
a copy of a segment of L, or do I actually get a pointer to something
inside L ? Is the above function length O(n) or probably O(n^2) ? 
Where are such implementation things (well) said ?

Thanks,

     franck



More information about the Python-list mailing list