unzip function?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jan 18 10:27:35 EST 2012


On 2012年1月18日 09:33:34 -0500, Neal Becker wrote:
> python has builtin zip, but not unzip

That's because zip is (almost) its own inverse.
 
> 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 does a lot of unnecessary work.
a, b = zip(*sorted(zip(x,y)))
> That zip (*sorted...
>> does the unzipping.
>> But it's less than intuitively obvious.

*shrug*
If you understand what zip does, it should be obvious.
> I'm thinking unzip should be a builtin function, to match zip.

Just create your own utility function. Not everything needs to be a 
built-in.
def unzip(iterable):
 return zip(*iterable)
Hardly seems worthwhile.
-- 
Steven


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /