array alice of [:-0] ??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • guthrie

    array alice of [:-0] ??

    Beginner question! :-)

    x=[1,2,3,4]
    for i in range(len(x)):
    print x[:-i]
    >>[]
    >>[1,2,3]
    >>[1,2]
    >>[1]
    1) The x[:-0] result seems inconsistent to me;
    I get the idea that -0=0, so it is taken as x[:0] -[]
    2) how then should one do this basic left-recursive subsetting (easily).

    Thanks.


    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  • John Machin

    #2
    Re: array alice of [:-0] ??

    On 18/07/2006 11:17 PM, guthrie wrote:
    Beginner question! :-)
    >
    x=[1,2,3,4]
    for i in range(len(x)):
    print x[:-i]
    >
    >>[]
    >>[1,2,3]
    >>[1,2]
    >>[1]
    >
    1) The x[:-0] result seems inconsistent to me;
    I get the idea that -0=0, so it is taken as x[:0] -[]
    2) how then should one do this basic left-recursive subsetting (easily).
    >
    >
    |>for i in range(len(x), -1, -1):
    .... print x[:i]
    ....
    [1, 2, 3, 4]
    [1, 2, 3]
    [1, 2]
    [1]
    []

    Comment

    • Boris Borcic

      #3
      Re: array alice of [:-0] ??

      guthrie wrote:
      Beginner question! :-)
      >
      x=[1,2,3,4]
      for i in range(len(x)):
      print x[:-i]
      >
      >>[]
      >>[1,2,3]
      >>[1,2]
      >>[1]
      >
      1) The x[:-0] result seems inconsistent to me;
      I get the idea that -0=0, so it is taken as x[:0] -[]
      that's what you get.
      2) how then should one do this basic left-recursive subsetting (easily).
      I am not sure what you mean, but replacing x[:-i] by x[:len(x)-i] you will get
      continuous behavior at i==0.

      Comment

      • Antoon Pardon

        #4
        Re: array alice of [:-0] ??

        On 2006-07-18, guthrie <guthrie@mum.ed uwrote:
        Beginner question! :-)
        >
        x=[1,2,3,4]
        for i in range(len(x)):
        print x[:-i]
        >
        >[]
        >[1,2,3]
        >[1,2]
        >[1]
        >
        1) The x[:-0] result seems inconsistent to me;
        I get the idea that -0=0, so it is taken as x[:0] -[]
        That is correct. Negative indexes are a handy shorthand, but
        they can give unexpected/strange results in a number of cases.
        2) how then should one do this basic left-recursive subsetting (easily).
        x=[1,2,3,4]
        lng = len(x)
        for i in range(lng):
        print x[:lng-i]

        --
        Antoon Pardon

        Comment

        • guthrie

          #5
          Re: array slice of [:-0] ??

          Thanks all!!
          ---------------------

          guthrie wrote:
          Beginner question! :-)
          >
          x=[1,2,3,4]
          for i in range(len(x)):
          print x[:-i]
          >
          >>[]
          >>[1,2,3]
          >>[1,2]
          >>[1]
          >
          1) The x[:-0] result seems inconsistent to me;
          I get the idea that -0=0, so it is taken as x[:0] -[]
          2) how then should one do this basic left-recursive subsetting (easily).
          >
          Thanks.
          >

          ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
          http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
          ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

          Comment

          Working...