Pythonic style
Léo El Amri
leo at superlel.me
Mon Sep 21 09:46:39 EDT 2020
On 21/09/2020 15:15, Tim Chase wrote:
> You can use tuple unpacking assignment and Python will take care of
> the rest for you:
>
> so you can do
>
> def fn(iterable):
> x, = iterable
> return x
>
> I'm not sure it qualifies as Pythonic, but it uses Pythonic features
> like tuple unpacking and the code is a lot more concise.
I guess you just beat the topic. I think it is Pythonic and I'd be
surprised if someone came with something more Pythonic.
FI: The behavior of this assignation is detailed here:
https://docs.python.org/3/reference/simple_stmts.html#assignment-statements
More information about the Python-list
mailing list