Re: Looping over lists

2007-05-06 Thread Gabriel Genellina
En Sat, 05 May 2007 05:15:32 -0300, kaens <[EMAIL PROTECTED]> escribió: > I think the for i in range() is more readable (Maybe because I'm > coming from a c-style syntax language background) - but what would > the benefits of using enumerate be (other that being more . . . > pythonesque?) If y

Re: Looping over lists

2007-05-05 Thread Alex Martelli
Dustan <[EMAIL PROTECTED]> wrote: > On May 5, 3:15 am, kaens <[EMAIL PROTECTED]> wrote: > > I think the for i in range() is more readable (Maybe because I'm > > coming from a c-style syntax language background) - but what would > > the benefits of using enumerate be (other that being more . . . >

Re: Looping over lists

2007-05-05 Thread Paul Rubin
Dustan <[EMAIL PROTECTED]> writes: > > I think the for i in range() is more readable (Maybe because I'm > > coming from a c-style syntax language background) - but what would > > the benefits of using enumerate be (other that being more . . . > > pythonesque?) > > It doesn't create a whole new li

Re: Looping over lists

2007-05-05 Thread Dustan
On May 5, 3:15 am, kaens <[EMAIL PROTECTED]> wrote: > I think the for i in range() is more readable (Maybe because I'm > coming from a c-style syntax language background) - but what would > the benefits of using enumerate be (other that being more . . . > pythonesque?) It doesn't create a whole n

Re: Looping over lists

2007-05-05 Thread kaens
I think the for i in range() is more readable (Maybe because I'm coming from a c-style syntax language background) - but what would the benefits of using enumerate be (other that being more . . . pythonesque?) On 5/5/07, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Fri, 4 May 2007 19:26:17 -

Re: Looping over lists

2007-05-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, prad wrote: > On Friday 04 May 2007 18:40:53 Tommy Grav wrote: >> Can anyone help me with the right approach for this >> in python? > > for each in a: > for item in a[a.index(each)+1:]: > print each,item > > will produce > > 1 2 > 1 3 > 1 4 > 1 5 > 2 3 > 2 4

Re: Looping over lists

2007-05-04 Thread Peter Otten
prad wrote: > On Friday 04 May 2007 18:40:53 Tommy Grav wrote: >> Can anyone help me with the right approach for this >> in python? > > for each in a: > for item in a[a.index(each)+1:]: > print each,item > > will produce > > 1 2 > 1 3 > 1 4 > 1 5 > 2 3 > 2 4 > 2 5 > 3 4 > 3 5 > 4 5

Re: Looping over lists

2007-05-04 Thread Paul Rubin
Tommy Grav <[EMAIL PROTECTED]> writes: > In C this would be equivalent to: > for(i = 0; i < n; i++) { > for(j=i+1; j < n; j++) { > print a[i], a[j] for i in xrange(n): for j in xrange(i+1, n): print a[i], a[j] -- http://mail.python.org/mailman/listinfo/python-list

Re: Looping over lists

2007-05-04 Thread Peter Otten
Tommy Grav wrote: > I have a list: > >a = [1., 2., 3., 4., 5.] > > I want to loop over a and then > loop over the elements in a > that is to the right of the current > element of the first loop > > In C this would be equivalent to: > > for(i = 0; i < n; i++) { > for(j=i+1; j < n; j++)

Re: Looping over lists

2007-05-04 Thread prad
On Friday 04 May 2007 18:40:53 Tommy Grav wrote: > Can anyone help me with the right approach for this > in python? for each in a: for item in a[a.index(each)+1:]: print each,item will produce 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 a.index(each) gives the index of the each value i

Re: Looping over lists

2007-05-04 Thread Alex Martelli
Tommy Grav <[EMAIL PROTECTED]> wrote: > I have a list: > >a = [1., 2., 3., 4., 5.] > > I want to loop over a and then > loop over the elements in a > that is to the right of the current > element of the first loop > > In C this would be equivalent to: > > for(i = 0; i < n; i++) { > for