which datastructure for fast sorted insert?

notnorwegian at yahoo.se notnorwegian at yahoo.se
Sun May 25 21:14:51 EDT 2008


On 26 Maj, 03:04, notnorweg... at yahoo.se wrote:
> On 26 Maj, 01:30, I V <ivle... at gmail.com> wrote:
>
>
>
> > On Sun, 25 May 2008 15:49:16 -0700, notnorwegian wrote:
> > > i meant like set[pos], not iterate but access a specific position in the
> > > set.
>
> > If you need to access arbitrary elements, use a list instead of a set
> > (but you'll get slower inserts). OTOH, if you just need to be able to get
> > the next item from the set, you can use an iterator:
>
> > > now i have to do:
> > > s = toSet.pop()
> > > toSet.add(s)
>
> > i = iter(toSet)
>
> > s = i.next()
>
> > > if i want to get the url of the next item in a set, how would i do that?
> > > i can do this with a list:
>
> > > def scrapeSitesX(startAddress, toList, listPos): return
> > > scrapeSites(toList[listPos], toList, listPos+1) to use recursion with a
> > > list.
> > > i can work around that but it doesnt get as elegant.
>
> > Do you have to use recursion here? Why not:
>
> > for site in toList:
> >         scrape(site)
>
> i have tried both.
>
> anyway how do i concatenate sets? which i have to if use to funcions
> like you suggest.
>
> and also when iterating a set is there any other way to avoid
> exceptions than have a counter and compare to len(set).
> is there no method that cna check if iter != None

nevermind got it how to concatenate.

but no builtin method for concatenating right?



More information about the Python-list mailing list