Re: [Tutor] extracting numbers from a list

2006-10-18 Thread Danny Yoo
On Wed, 18 Oct 2006, kumar s wrote: > I am not sure if I got your opinion about the way I solved. Hi Kumar, I was replying to your question: http://mail.python.org/pipermail/tutor/2006-October/050064.html in which you showed a program that had problems. I'm assuming that you haven't f

Re: [Tutor] extracting numbers from a list

2006-10-18 Thread kumar s
Thank you Danny. I am going over your email and trying to understand (i am a biologist with bioinformatics training). I am not sure if I got your opinion about the way I solved. do you mean that there is something wrong with the way i solved it. I am not sure If I explained the problem correctl

Re: [Tutor] extracting numbers from a list

2006-10-17 Thread Danny Yoo
On Mon, 16 Oct 2006, kumar s wrote: > I have a simple question to ask tutors: > > list A : > > a = [10,15,18,20,25,30,40] Hi Kumar, If you're concerned about correctness, I'd recommend that you try thinking about the problem inductively. An inductive definition for what you're asking is st

Re: [Tutor] extracting numbers from a list

2006-10-17 Thread kumar s
In continuation to : Re: [Tutor] extracting numbers from a list hello list I have coordinates for exons (chunks of sequence). For instance: 10 - 50 A 10 - 20 B 35 - 50 B 60 - 70 A 60 - 70 B 80 - 100 A 80 - 100 B (The above coordinates and names are easier than in dat) Here my aim is to

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread John Fouhy
On 17/10/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote: > My solution : (i have tested it) As long as we're all taking turns, what about a functional approach: >>> a = [10, 15, 18, 20, 25, 30, 40] >>> def pairs(lst): ... return list.__add__([(lst[0], lst[1])], zip(map((1).__add__, lst[1:]), lst

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread Asrarahmed Kadri
I agree. Regards,   Asrar  On 10/17/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Asrarahmed Kadri wrote:> 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] += 1Note that this changes the original list, w

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread Kent Johnson
Asrarahmed Kadri wrote: > 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 that this changes the original list, which may or may not be acceptable. Normally you would expect a p

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread Asrarahmed Kadri
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

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread Alan Gauld
"wesley chun" <[EMAIL PROTECTED]> wrote in message > look very carefully at variables 'fy' vs. 'last', what you do with > them, and when, and you should be able to figure out your homework > assignment problem. Hmmm, "homework assignment" was probably what I was missing Alan G. ___

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread Alan Gauld
"kumar s" <[EMAIL PROTECTED]> 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[

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread Ziad Rahhal
On 10/16/06, kumar s <[EMAIL PROTECTED]> wrote: hi :I have a simple question to ask tutors:list A :a = [10,15,18,20,25,30,40]I want to print10 15 (first two elements)16 18 (16 is last number +1)19 2021 2526 3031 40 >>> fx = a[0]>>> fy = a[1]>>> b = a[2:]>>> ai = iter(b)>>> last = ai.next()>>> for j

Re: [Tutor] extracting numbers from a list

2006-10-16 Thread wesley chun
> I want to print > 10 15 (first two elements) > 16 18 (16 is last number +1) >: > >>> 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 look very carefully a

[Tutor] extracting numbers from a list

2006-10-16 Thread kumar s
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,l