Re: [Tutor] how to convert array into tuple

2007-09-28 Thread Noufal Ibrahim
bhaaluu wrote: > Can you explain how this works? How would this be written in > a "conventional" way? I'm not sure if this is addressed to me but I'll reply anyway. :) foo = [1,2,3,4,5,6] [(foo[i],foo[i+1]) for i in range(0,len(foo),2)] range(0,len(foo)) would create a list of consecut

Re: [Tutor] how to convert array into tuple

2007-09-27 Thread bhaaluu
Can you explain how this works? How would this be written in a "conventional" way? >>> foo = [1,2,3,4,5,6] >>> [(foo[i],foo[i+1]) for i in range(0,len(foo),2)] [(1, 2), (3, 4), (5, 6)] >>> foo = [1,2,3,4,5,6,7,8,9] >>> [(foo[i],foo[i+1]) for i in range(0,len(foo)-4,2)] [(1, 2), (3, 4), (5, 6)] Al

Re: [Tutor] how to convert array into tuple

2007-09-27 Thread Kent Johnson
Noufal Ibrahim wrote: > This seems to work although I'd like comments from the more experienced > Pythonistas out there. > > >>> foo > [1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> [(foo[i],foo[i+1]) for i in range(0,len(foo)-2,2)] > [(1, 2), (3, 4), (5, 6), (7, 8)] This problem is a perennial favorite o

Re: [Tutor] how to convert array into tuple

2007-09-27 Thread Noufal Ibrahim
Fangwen Lu wrote: > Dear all- > > If I have an array array([1, 2, 3, 4, 5, 6]), and I want to get > ((1,2),(3,4),(5,6)). What should I do? This seems to work although I'd like comments from the more experienced Pythonistas out there. >>> foo [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> [(foo[i],foo[i+1]

Re: [Tutor] how to convert array into tuple

2007-09-26 Thread Eric Brunson
Fangwen Lu wrote: > Dear all- > > If I have an array array([1, 2, 3, 4, 5, 6]), and I want to get > ((1,2),(3,4),(5,6)). What should I do? First, you read some documentation and tutorials on the language, then you iterate over the list and build tuples out of the elements. > > Thank you! >

Re: [Tutor] how to convert array into tuple

2007-09-26 Thread Ricardo Aráoz
Fangwen Lu wrote: > Dear all- > > If I have an array array([1, 2, 3, 4, 5, 6]), and I want to get > ((1,2),(3,4),(5,6)). What should I do? > tuple([j for (i,j) in enumerate(zip(x, x[1:])) if i % 2 == 0]) ___ Tutor maillist - Tutor@python.org http:

[Tutor] how to convert array into tuple

2007-09-26 Thread Fangwen Lu
Dear all- If I have an array array([1, 2, 3, 4, 5, 6]), and I want to get ((1,2),(3,4),(5,6)). What should I do? Thank you! Fangwen ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor