Python's simplicity philosophy
Terry Reedy
tjreedy at udel.edu
Thu Nov 20 09:31:27 EST 2003
"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message
news:7xr803ipj4.fsf at ruckus.brouhaha.com...
> 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.
This 'generalized informal' meaning is new to me also ;-).
> 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.
I believe this requires list to be sorted, generally O(nlogn) if not
already so, while hash solution (sets, dict) is O(n) (+O(n) temporary
space). So either method can be 'best' in particular situation.
Terry J. Reedy
More information about the Python-list
mailing list