3 ms·
Perhaps `zip' could help address some of your points? > 2. List comprehensions kind of suck. [(a, b) for a in as for b in bs] is a cartesian product and not a
by eru 16y ago
Perhaps `zip' could help address some of your points?
> 2. List comprehensions kind of suck. [(a, b) for a in as for b in bs] is a cartesian product and not a zip? Really?
Strange. I would say it sucked if it was the other way round. You can use the `zip' function, if you want a zip.
zip (as, bs)
> 3. Loops don't help this either: There's no equivalent of the Lisp (loop for x in xs for y in ys do (stuff x y)). I have to explicitly loop over the index. This pisses me off.
Try the function `enumerate' and `zip'. E.g.
for x,y in zip(xs, ys): stuff (x,y)
If you need an explicit index for your stuff:
for (i, (x,y)) in zip(xs, ys): stuff (x,y)
> 4. I feel that I am generally shoehorned into creating and assigning more objects than I would like.
I agree, only the other way around. Python is much too destructive and relies on in-place updating. E.g. recently we got `sorted' that doesn't sort in-place but return a sorted array --- but the `shuffle' function still works only in-place. Also dicts are destructive. There should be a persistent (i.e. non-ephemeral) data structure for key-value-mappings in the standard library.