[Tutor] extracting numbers from a list
Asrarahmed Kadri
ajkadri at googlemail.com
Tue Oct 17 02:42:07 CEST 2006
My solution : (i have tested it)
list1 = [10,15,18,20,25,30,40]
for i in range(len(list1)-1):
print list1[i],list1[i+1]
list1[i+1] += 1
Note:
# print the consecutive elements; for the first pass of the loop the
elements are unchanged, for the remaining we add one.
On 10/16/06, kumar s <ps_python at yahoo.com> wrote:
>
> hi :
>
> I have a simple question to ask tutors:
>
> list A :
>
> 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
> 21 25
> 26 30
> 31 40
>
> >>> fx = a[0]
> >>> fy = a[1]
> >>> b = a[2:]
> >>> ai = iter(b)
> >>> last = ai.next()
> >>> for j in ai:
> ... print fy+1,last
> ... last = j
> ...
> 16 18
> 16 20
> 16 25
> 16 30
>
>
> can any one help please.
>
> thank you
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061017/d059a958/attachment.htm
More information about the Tutor
mailing list