osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tutor] beginning to code


On Wed, Sep 13, 2017 at 3:22 AM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> Oops! Yes, i did put a superfluous anonymous function in
> there, my bad O:-) Although, to my defense, (and although i
> never use this style in real code, but i'm trying to save
> face here #_o, so bear with me...) the lambda does make the
> call to map a "little" more clearer. For instance, when we
> juxtapose:
>
>     map(int, flist)
>
> with:
>
>     map(lambda f:int(f), flist)
>
> We get a little more insight into the internal workings of
> map in the second example, specifically, that each `f` in
> `flist` is being cast to integer.

The point of map() is to map a function over a collection. Its inner
workings are no more exposed by the use of a pass-through lambda
function than without.

> So, what are your answers to my four questions:
>
>     (1) Is it a speed issue? Then prove it.
>
>     (2) Is it a readability issue? If so, then that's an
>     opinion _you_ get to have.
>
>     (3) Is it a matter of "python purity"?  If so, then map
>     should be removed from the language, and don't forget to
>     remove reduce and filter while you're at it, and then,
>     you may want to grab a shield because the functional
>     fanboys will be all over you like white on rice! (psst:
>     here comes Rustom Mody now!!!)
>
>     (4) Something else...?
>
>> Of course Python is going to look worse if you add stuff
>> like that to your code.
>
> The lambda was an accident, perhaps even a happy accident,
> but my four questions and my original intent stands valid
> even in light of my simple mistake. Now dammit, answer the
> questions! :-)
> --
> https://mail.python.org/mailman/listinfo/python-list