which datastructure for fast sorted insert?

Rares Vernica rares at ics.uci.edu
Sun May 25 02:56:10 EDT 2008


use a set to store them:

>>> s=set()
>>> s.add('a')
>>> s.add('b')
>>> s
set(['a', 'b'])
>>> s.add('a')
>>> s
set(['a', 'b'])
>>> s.add('c')
>>> s
set(['a', 'c', 'b'])
>>> 

it does remove duplicates, but is it not ordered. to order it you can
use:

>>> l=list(s)
>>> l.sort()
>>> l
['a', 'b', 'c']

hth,
Rares



More information about the Python-list mailing list