slice lists

jbperez808 at yahoo.com jbperez808 at yahoo.com
Mon Sep 19 15:46:40 EDT 2005


Reading:

  http://docs.python.org/ref/slicings.html

it would seem to indicate that the ff will work:

  L=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

however, you get:

  >>> l[3:4:,5:8:]
  Traceback (most recent call last):
    File "<pyshell#153>", line 1, in ?
      l[3:4:,5:8:]
  TypeError: list indices must be integers

in Python 2.3...  are they only available in 2.4?


Also,

  http://www.python.org/doc/2.3/whatsnew/section-slices.html

mentions that:

  "Ever since Python 1.4, the slicing syntax
  has supported an optional third 'step' or 'stride'
  argument. For example, these are all legal Python syntax:
  L[1:10:2], L[:-1:1], L[::-1]."

and yet, we see in:

  http://pyds.muensterland.org/weblog/2004/12/25.html

that something as simple as:

  l = range(0,10)
  print l[1:5]     # this works
  print l[1:5:2]   # this barfs 

fails in Python 2.2.  What gives?




More information about the Python-list mailing list