NoneType List

Chris Angelico rosuav at gmail.com
Sat Dec 31 23:23:59 EST 2022


On Sun, 1 Jan 2023 at 15:16, <avi.e.gross at gmail.com> wrote:
>
> Chris,
>
> There is much to say about consistent behavior as compared to flexibility
> and convenience.
>
>  I have seen other languages provide functions for example, where the result
> can vary and often cause confusion. R had a function that would sometimes
> notice the result could be simplified and return that. Guess what? It caused
> lots of problems and an option was added that said it should NOT simplify
> and always return the same kind of thing.

The option was presumably added because backward compatibility is
important, but it would have been better to not need the option in the
first place.

> As a dumb example, what does a simple function like max() return if fed just
> integers, just floating point or a combination of both? It seems to return
> whatever type the maximum indicates. But it also accepts characters and
> sorts them appropriately returning type 'str' and probably accepts and
> returns  all kinds of objects if you specify a key function.
>
> Is that so much different than we are discussing in that there isn't any
> absolute consistency and things can go various ways in terms of return
> value? Heck, I can even make max() return None!
>

... yes? So? It still always returns the largest item in the list, for
some definition of "largest". You'll never have that value returned
wrapped up in a single-element list, though.

ChrisA


More information about the Python-list mailing list