A Q concerning map (a comparison to Maple V)
Franz GEIGER
fgeiger at datec.at
Wed Dec 27 01:47:19 EST 2000
> map(replace, ["abc", "cde"], ["c"]*2, ["C"]*2)
>
That's it, but doesn't look that beautiful.
> whereas with you proposal this would give you:
>
> ["abc", "CDe"]
No, with my proposal nothing would happen, because there is no "cd"
anywhere. Be aware, the list is the list replace has to be applied on, not
the strings within it.
> Excuse me if I misinterpreted your proposal, but if the
Excused ;-)
Best regards
Franz GEIGER
"Peter Schneider-Kamp" <peter at schneider-kamp.de> wrote in message
news:mailman.977570347.5588.python-list at python.org...
> Franz GEIGER schrieb:
> >
> > 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?
>
> 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, s.t.
>
> map(f, a_1, .., a_n, b_1, .., b_m)
>
> for f being a (m+n)-ary function, a_1 to a_n being sequence
> parameters and b_1 to b_m non-sequence parameters would yield
>
> maxlen = max(map(len,[a_1, .., a_n]))
> map(f, a_1, .., a_n, [b_1]*maxlen, .., [b_m]*maxlen)
>
> But how would you decide if "abc" is a sequence parameter
> or not? To keep your example, what would
>
> map(replace, ["abc", "cde"], "cd", "CD")
>
> mean? At the moment this gives you:
>
> ["abC", "cDe"]
>
> whereas with you proposal this would give you:
>
> ["abc", "CDe"]
>
> Excuse me if I misinterpreted your proposal, but if the
> above is what you mean, I think this a Bad Idea(tm).
>
> merry-xmas-shopping-ly y'rs
> Peter
>
More information about the Python-list
mailing list