Re: Efficiently Split A List of Tuples

2005-07-18 Thread Ron Adam
Simon Dahlbacka wrote: > Oooh.. you make my eyes bleed. IMO that proposal is butt ugly (and > looks like the C++.NET perversions.) I haven't had the displeasure of using C++.NET fortunately. point = [5,(10,20,5)] size,t = point x,y,z = t size,x,y,z = point[0], point[1][0], poi

Re: Efficiently Split A List of Tuples

2005-07-18 Thread Ron Adam
Raymond Hettinger wrote: > [Ron Adam] > >>Currently we can implicitly unpack a tuple or list by using an >>assignment. How is that any different than passing arguments to a >>function? Does it use a different mechanism? > > > It is the same mechanism, so it is also only appropriate for low > v

Re: Efficiently Split A List of Tuples

2005-07-18 Thread Steven D'Aprano
On Sun, 17 Jul 2005 19:38:29 -0700, Raymond Hettinger wrote: > Executive summary: Python's for-loops are both elegant and fast. It > is a mistake to habitually avoid them. And frequently much more readable and maintainable than the alternatives. I cringe when I see well-meaning people trying t

Re: Efficiently Split A List of Tuples

2005-07-18 Thread Raymond Hettinger
[Ron Adam] > Currently we can implicitly unpack a tuple or list by using an > assignment. How is that any different than passing arguments to a > function? Does it use a different mechanism? It is the same mechanism, so it is also only appropriate for low volumes of data: a, b, c = *args

Re: Efficiently Split A List of Tuples

2005-07-18 Thread Simon Dahlbacka
Oooh.. you make my eyes bleed. IMO that proposal is butt ugly (and looks like the C++.NET perversions.) -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficiently Split A List of Tuples

2005-07-17 Thread Ron Adam
Raymond Hettinger wrote: >>Variant of Paul's example: >> >>a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10)) >>zip(*a) >> >>or >> >>[list(t) for t in zip(*a)] if you need lists instead of tuples. > > > > [Peter Hansen] > >>(I believe this is something Guido considers an "abuse of *args", but I >>jus

Re: Efficiently Split A List of Tuples

2005-07-17 Thread Raymond Hettinger
[Richard] > I know I can use a 'for' loop and create two new lists > using 'newList1.append(x)', etc. Is there an efficient way > to create these two new lists without using a slow for loop? If trying to optimize before writing and timing code, then at least validate your assumptions. In Python,

Re: Efficiently Split A List of Tuples

2005-07-17 Thread Raymond Hettinger
> Variant of Paul's example: > > a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10)) > zip(*a) > > or > > [list(t) for t in zip(*a)] if you need lists instead of tuples. [Peter Hansen] > (I believe this is something Guido considers an "abuse of *args", but I > just consider it an elegant use of zip() co

Re: Efficiently Split A List of Tuples

2005-07-14 Thread Peter Hansen
Richard wrote: > On Wed, 13 Jul 2005 20:53:58 -0400, Peter Hansen wrote: >>a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10)) >>zip(*a) > This seems to work. Thanks. > > Where do I find documentation on "*args"? In the language reference: http://docs.python.org/ref/calls.html#calls -Peter -- http:/

Re: Efficiently Split A List of Tuples

2005-07-14 Thread Richard
On Wed, 13 Jul 2005 20:53:58 -0400, Peter Hansen wrote: > a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10)) > zip(*a) > This seems to work. Thanks. Where do I find documentation on "*args"? -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficiently Split A List of Tuples

2005-07-13 Thread Peter Hansen
Joseph Garvin wrote: > Peter Hansen wrote: > >> (I believe this is something Guido considers an "abuse of *args", but >> I just consider it an elegant use of zip() considering how the >> language defines *args. YMMV] >> >> -Peter >> >> > An abuse?! That's one of the most useful things to do w

Re: Efficiently Split A List of Tuples

2005-07-13 Thread Joseph Garvin
Peter Hansen wrote: >(I believe this is something Guido considers an "abuse of *args", but I >just consider it an elegant use of zip() considering how the language >defines *args. YMMV] > >-Peter > > An abuse?! That's one of the most useful things to do with it. It's transpose. -- http://ma

Re: Efficiently Split A List of Tuples

2005-07-13 Thread Peter Hansen
Richard wrote: > I have a large list of two element tuples. I want two separate > lists: One list with the first element of every tuple, and the > second list with the second element of every tuple. Variant of Paul's example: a = ((1,2), (3, 4), (5, 6), (7, 8), (9, 10)) zip(*a) or [list(t) for

Re: Efficiently Split A List of Tuples

2005-07-13 Thread Paul Rubin
Richard <[EMAIL PROTECTED]> writes: > I have a large list of two element tuples. I want two separate > lists: One list with the first element of every tuple, and the > second list with the second element of every tuple. > > I know I can use a 'for' loop and create two new lists > using 'newList1.a

Re: Efficiently Split A List of Tuples

2005-07-13 Thread Cyril Bazin
if t is your data, you can use: l1, l2 = zip(*t) Cyril On 7/14/05, Richard <[EMAIL PROTECTED]> wrote: I have a large list of two element tuples.  I want two separatelists: One list with the first element of every tuple, and thesecond list with the second element of every tuple.Each tuple contains