which datastructure for fast sorted insert?

notnorwegian at yahoo.se notnorwegian at yahoo.se
Sun May 25 03:10:45 EDT 2008


On 25 Maj, 08:56, Rares Vernica <ra... at ics.uci.edu> wrote:
> 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

sets dont seem to be so good because there is no way to iterate them.

s.pop()  	 	remove and return an arbitrary element from s; raises
KeyError if empty

i dont want to remove i just want to get the string that is stored
there.



More information about the Python-list mailing list