> The corner case is when dealing with empty lists and there aren't
> enough items to unpack.
>
>
Another solution to zip(), with a slightly different behaviour for conner
cases
>>> a = (1,2,3)
>>> b = (1,2,3)
>>> c = (1,2,3,4)
>>> zip(a,b)
[(1, 1), (2, 2), (3, 3)]
>>> map(None,a,b)
[(1, 1),
On Wed, Dec 3, 2008 at 11:19 AM, Andreas Waldenburger <[EMAIL PROTECTED]>wrote:
> On Wed, 3 Dec 2008 07:08:52 -0800 (PST) Janto Dreijer
> <[EMAIL PROTECTED]> wrote:
>
> > I'd like to point out that since your where thinking in terms of
> > matplotlib, you might actually find numpy's own transpose
On Wed, 3 Dec 2008 07:08:52 -0800 (PST) Janto Dreijer
<[EMAIL PROTECTED]> wrote:
> I'd like to point out that since your where thinking in terms of
> matplotlib, you might actually find numpy's own transpose useful,
> instead of using zip(*seq) :)
>
This was, of course, to be expected. :)
Whenev
I'd like to point out that since your where thinking in terms of
matplotlib, you might actually find numpy's own transpose useful,
instead of using zip(*seq) :)
untested:
t = linspace(0,2*pi*3)
seq = asarray(zip(t, sin(t)))
t, y = seq.T # or seq.transpose() or numpy.transpose(seq)
pylab.plot(t,y
On Wed, 3 Dec 2008 02:11:51 -0800 (PST) alex23 <[EMAIL PROTECTED]>
wrote:
> On Dec 3, 6:51 pm, Andreas Waldenburger <[EMAIL PROTECTED]> wrote:
> > On Tue, 02 Dec 2008 18:16:13 -0800 Bryan Olson
> > > zip as its own inverse might be even easier to comprehend if we
> > > call zip by its more traditi
On Dec 3, 6:51 pm, Andreas Waldenburger <[EMAIL PROTECTED]> wrote:
> On Tue, 02 Dec 2008 18:16:13 -0800 Bryan Olson
> > zip as its own inverse might be even easier to comprehend if we call
> > zip by its more traditional name, "transpose".
>
> Sounds like a Py4k change to me.
Nah, just add the fol
On Tue, 02 Dec 2008 18:16:13 -0800 Bryan Olson
<[EMAIL PROTECTED]> wrote:
> zip as its own inverse might be even easier to comprehend if we call
> zip by its more traditional name, "transpose".
>
Sounds like a Py4k change to me.
/W
--
My real email address is constructed by swapping the domain
Zac Burns wrote:
> More succinct failure:
>
> keys, values = zip(*{}.iteritems())
Simple fix:
some_iterable = {}.iteritems()
keys, values = zip(*list(some_iterable))
or:
keys, values = zip(*(some_iterable
if isinstance(some_iterable, (list, tuple))
John Machin wrote:
Here's a version that makes it slightly easier to comprehend:
Q: I know how to zip sequences together:
| >>> a = (1, 2, 3)
| >>> b = (4, 5, 6)
| >>> z = zip(a, b)
| >>> z
| [(1, 4), (2, 5), (3, 6)]
but how do I reverse the process?
A: Use zip()!
| >>> a2, b2 = zip(*z)
| >>> a
Zac Burns wrote:
There is a problem with this however, which prompted me to actually
write an unzip function.
One might expect to be able to do something like so (pseudocode)...
def filesAndAttributes():
files = walk()
attributes = [attr(f) for f in files]
return zip(files, attributes)
More succinct failure:
keys, values = zip(*{}.iteritems())
--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
On Tue, Dec 2, 2008 at 4:47 PM, Zac Burns <[EMAIL PROTECTED]> wrote:
> There is a problem with this however, which prompted me to actual
There is a problem with this however, which prompted me to actually
write an unzip function.
One might expect to be able to do something like so (pseudocode)...
def filesAndAttributes():
files = walk()
attributes = [attr(f) for f in files]
return zip(files, attributes)
files, attributes
On Dec 3, 7:12 am, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Andreas Waldenburger wrote:
> > we all know about the zip builtin that combines several iterables into
> > a list of tuples.
>
> > I often find myself doing the reverse, splitting a list of tuples into
> > several lists, each correspondi
On Tue, 02 Dec 2008 21:12:19 +0100 Stefan Behnel <[EMAIL PROTECTED]>
wrote:
> Andreas Waldenburger wrote:
> > [snip]
> > This is of course trivial to do via iteration or listcomps, BUT, I
> > was wondering if there is a function I don't know about that does
> > this nicely?
>
> I think you're aski
Andreas Waldenburger wrote:
> we all know about the zip builtin that combines several iterables into
> a list of tuples.
>
> I often find myself doing the reverse, splitting a list of tuples into
> several lists, each corresponding to a certain element of each tuple
> (e.g. matplotlib/pyplot needs
Hi all,
we all know about the zip builtin that combines several iterables into
a list of tuples.
I often find myself doing the reverse, splitting a list of tuples into
several lists, each corresponding to a certain element of each tuple
(e.g. matplotlib/pyplot needs those, rather than lists of po
16 matches
Mail list logo