Re: which datastructure for fast sorted insert?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc 'BlackJack' Rintsch

    Re: which datastructure for fast sorted insert?

    On Sun, 25 May 2008 00:10:45 -0700, notnorwegian wrote:
    sets dont seem to be so good because there is no way to iterate them.
    Err:

    In [82]: for x in set(['a', 'b', 'c']):
    ....: print x
    ....:
    a
    c
    b

    Ciao,
    Marc 'BlackJack' Rintsch
  • notnorwegian@yahoo.se

    #2
    Re: which datastructure for fast sorted insert?

    On May 25, 9:32 am, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
    On Sun, 25 May 2008 00:10:45 -0700, notnorwegian wrote:
    sets dont seem to be so good because there is no way to iterate them.
    >
    Err:
    >
    In [82]: for x in set(['a', 'b', 'c']):
       ....:     print x
       ....:
    a
    c
    b
    >
    Ciao,
            Marc 'BlackJack' Rintsch

    i meant like set[pos], not iterate but access a specific position in
    the set.

    now i have to do:
    s = toSet.pop()
    toSet.add(s)

    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(st artAddress, toList, listPos):
    return scrapeSites(toL ist[listPos], toList, listPos+1)
    to use recursion with a list.
    i can work around that but it doesnt get as elegant.

    Comment

    • I V

      #3
      Re: which datastructure for fast sorted insert?

      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(st artAddress, toList, listPos): return
      scrapeSites(toL ist[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)

      Comment

      • notnorwegian@yahoo.se

        #4
        Re: which datastructure for fast sorted insert?

        On 26 Maj, 01:30, I V <ivle...@gmail. comwrote:
        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(st artAddress, toList, listPos): return
        scrapeSites(toL ist[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

        Comment

        • notnorwegian@yahoo.se

          #5
          Re: which datastructure for fast sorted insert?

          On 26 Maj, 03:04, notnorweg...@ya hoo.se wrote:
          On 26 Maj, 01:30, I V <ivle...@gmail. comwrote:
          >
          >
          >
          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(st artAddress, toList, listPos): return
          scrapeSites(toL ist[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?

          Comment

          Working...