which datastructure for fast sorted insert?

Benjamin Kaplan benjamin.kaplan at case.edu
Sun May 25 08:34:02 EDT 2008


On Sun, May 25, 2008 at 3:10 AM, <notnorwegian at yahoo.se> wrote:

>
> > >>> 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.


The only requirement for iterating through something is that it defines an
__iter__ method, which set does. This means you can use iter(a_set) to get
your iterator, or just use "for i in a_set" to iterate automatically.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080525/3360f701/attachment-0001.html>


More information about the Python-list mailing list