Discussion: Introducing new operators for matrix computation
Paul Prescod
paul at prescod.net
Wed Jul 19 13:23:20 EDT 2000
Gareth McCaughan wrote:
>
> ...
>
> Well, I was making a broken assumption about the meaning of
> multiple comprehension indices: namely, that
> [(i,j) for i in [1,2], j in [1,2]]
> would evaluate to [(1,1), (2,2)] rather than [(1,1), (1,2), (2,1), (2,2)].
> If it's supposed to go the other way, then some of my other
> assumptions stop working. :-)
For exactly this reason I have proposed the following syntax:
[for i in [1,2]: for j in [1,2]: i, j ]
Which I think is more clear that it is not parallel.
> So [f(x) for x in collection] would turn into something like
>
> indices = collection.valid_indices()
> result = collection.clone()
> for index in indices:
> result[index] = f(collection[index])
...easier to just require the "collection" type to have an append
operator...
> ...
> With more than one collection being iterated over, as in
> [blah blah blah for x in xs, y in ys], the simplest thing
> would be to use the first collection mentioned as template
> and source of valid indices.
It's somewhat arbitrary but maybe it would work.
--
Paul Prescod - Not encumbered by corporate consensus
Just how compassionate can a Republican get before he has to leave the
GOP and join Vegans for Global Justice? ... One moment, George W. Bush
is holding a get-to-know-you meeting with a bunch of gay Republicans.
The next he is holding forth on education or the environment ... It is
enough to make a red-blooded conservative choke on his spotted-owl
drumstick. - April 29th, Economist
More information about the Python-list
mailing list