Python's simplicity philosophy

Paul Rubin http
Thu Nov 20 00:21:03 EST 2003


"Andrew Dalke" <adalke at mindspring.com> writes:
> I don't know what you mean by 'consing up a dictionary'
> taking up a 'woeful amount of overhead'.  It's a bit of overhead,
> but not woefully so.  (And what does 'consing' mean?  It's
> a Lisp thing, yes?  A 'cons cell' is the first / rest pair?)

Sorry, yeah, Lisp jargon.  A cons cell is a pair but "consing" has a
more generalized informal meaning of allocating any kind of storage on
the heap, which will have probably to be garbage collected later.
Consing up an object means building it up dynamically.

The way I usually uniq a list goes something like (untested):

  def uniq(list):
    p = 0 
    for i in xrange(1, len(list)):
       if list[i] != list[p]:
          p += 1
          list[p] = list[i]
    del list[p+1:]

So it just scans through the list once and then does a single del
operation.
         
> BTW, another option is
> 
>   unique_keys = list(sets.Set(lst))
> 
> but I still haven't internalized the sets module enough to
> remember it trippingly.

Yes, more consing :)




More information about the Python-list mailing list