Displaying multiple results in a list

Hans Nowak wurmy at earthlink.net
Mon Dec 3 17:01:05 EST 2001


Russell Briggs wrote:
> 
> Wanted to know if there was a way to specify ranges in a list such as:
> 
> newlist = ["1", "2", "3", "4", "5", "6"]
> 
> print newlist[1..3]  #ie:  print newlist[1], newlist[2], newlist[3]
> 
> Can something like this be done?
> 
> /russ

Well, you can use a slice, but this returns a new list object,
so it might not do exactly what you had in mind:

>>> z = range(10)
>>> z
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> z[1:4]
[1, 2, 3]
>>> 

--Hans



More information about the Python-list mailing list