[Tutor] extracting numbers from a list
Alan Gauld
alan.gauld at btinternet.com
Tue Oct 17 00:13:51 CEST 2006
"kumar s" <ps_python at yahoo.com> wrote
> a = [10,15,18,20,25,30,40]
>
> I want to print
> 10 15 (first two elements)
> 16 18 (16 is last number +1)
> 19 20
The simplest solution would seem to be a while loop:
print a[0], a[1] # special case
index = 1
while index < len(a):
print a[index-1]+1, a[index]
index += 1
But that seems too straightforward to be the solution,
so I assume I'm missing something?
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list