Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19097
| From | Hrvoje Niksic <hniksic@xemacs.org> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: unzip function? |
| Date | 2012-01-18 19:01 +0100 |
| Organization | B.net Hrvatska d.o.o. |
| Message-ID | <87aa5khoux.fsf@xemacs.org> (permalink) |
| References | <mailman.4828.1326897240.27778.python-list@python.org> |
Neal Becker <ndbecker2@gmail.com> writes: > python has builtin zip, but not unzip > > A bit of googling found my answer for my decorate/sort/undecorate problem: > > a, b = zip (*sorted ((c,d) for c,d in zip (x,y))) > > That zip (*sorted... > > does the unzipping. > > But it's less than intuitively obvious. > > I'm thinking unzip should be a builtin function, to match zip. "zip" and "unzip" are one and the same since zip is inverse to itself: >>> [(1, 2, 3), (4, 5, 6)] [(1, 2, 3), (4, 5, 6)] >>> zip(*_) [(1, 4), (2, 5), (3, 6)] >>> zip(*_) [(1, 2, 3), (4, 5, 6)] >>> zip(*_) [(1, 4), (2, 5), (3, 6)] What you seem to call unzip is simply zip with a different signature, taking a single argument: >>> def unzip(x): ... return zip(*x) ... >>> [(1, 2, 3), (4, 5, 6)] [(1, 2, 3), (4, 5, 6)] >>> unzip(_) [(1, 4), (2, 5), (3, 6)] >>> unzip(_) [(1, 2, 3), (4, 5, 6)] >>> unzip(_) [(1, 4), (2, 5), (3, 6)]
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
unzip function? Neal Becker <ndbecker2@gmail.com> - 2012-01-18 09:33 -0500
Re: unzip function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-18 15:27 +0000
Re: unzip function? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-18 11:20 -0500
Re: unzip function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-18 23:20 +0000
Re: unzip function? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-19 10:56 -0500
RE: unzip function? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-02-03 00:53 +0000
Re: unzip function? Hrvoje Niksic <hniksic@xemacs.org> - 2012-01-18 19:01 +0100
csiph-web