A Q concerning map (a comparison to Maple V)

Franz GEIGER fgeiger at datec.at
Tue Dec 26 10:01:07 EST 2000


> Note that the listcomps in 2.0 make scalar broadcast much easier to spell;
> e.g.
>
>     [replace(x, "c", "C") for x in ("abc", "cde")]
>     [x**2 + 5 for x in L]
>

Indeed, Peter, this is a Python way to do it. Yet I'm not very used to use
list comprehensions, but I'm working on that. Thank you!

Best regards
Franz GEIGER


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.977595008.22017.python-list at python.org...
> [Franz GEIGER]
> > > map(replace, ["abc", "cde"], "c", "C");
> > > instead of having to create a lambda function.
> > > Wouldn't it make sense to have that in Python too? Do there come
> > > more such opportunities into your mind?
>
> [Peter Schneider-Kamp]
> > If I get you right you intend this to mean:
> >
> >   map(replace, ["abc", "cde"], ["c"]*2, ["C"]*2)
> >
> > So basically your proposal is to reuse map parameters
> > which are no sequences in every iteration over the
> > parameters who are,
>
> It's hard to tell for sure, but that was my guess too.  In array
languages,
> this kind of thing is ubiquitous and is often called "scalar broadcast"
> (where a scalar is any atomic value (as opposed to an array), and is
> "broadcast" to every position of the arrays in which it's combined via
some
> operation).
>
> There was a long debate about this a few years ago on c.l.py, where I
> championed scalar broadcast in map specifically.  It collapsed under its
own
> hideous weight when-- as such things always do <wink> --that originally
> modest goal got hijacked by people seeking to extend the semantics to
every
> corner of the language.  That won't happen.
>
> > ...
> > But how would you decide if "abc" is a sequence parameter
> > or not?
>
> That is a problem!  Kinda.  Mostly people want to broadcast numbers (as in
> Franz's original example), and there's no problem there.  A cheap
workaround
> for sequences that are desired to be treated as scalars would have been to
> introduce a new builtin scalar() function, that simply hid the
> "sequenceness" of its argument from map.
>
> Note that the listcomps in 2.0 make scalar broadcast much easier to spell;
> e.g.
>
>     [replace(x, "c", "C") for x in ("abc", "cde")]
>     [x**2 + 5 for x in L]
>
> So the better solution is not to extend map, but to forget it <0.9 wink>.
>
> a-life-strategy-of-universal-applicability-ly y'rs  - tim
>
>







More information about the Python-list mailing list