Python Forum

Full Version: which is more Pythonic?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
which is more Pythonic?

...
    foo = [some,stuff,goes,here]
    bar = a_function(arg1,foo,arg3)
...
or:

...
   bar = a_function(arg1,[some,stuff,goes,here],arg3)
...
i, personally, find the first way easier to read. does that count?
The first one is better, because lesser code in function signature.
Additionally you have the reference to the list.

This can help you, if you have more than one function, which needs the list.
Then you can reuse the list in other function calls, but if you change the
list, everything is affected. This is why it's a bad idea to mutate a list
in a function.
i would say the first one slightly more readable as well
what about single values like returned from a funtion, that may, or may not, be a list?

...
    foo = a_function(whatever)
    bar = b_function(arg1,foo,arg3)
...
vs.

...
    bar = b_function(arg1,a_function(whatever),arg3)
...
Its almost always easier to read when you split it up like in the first example.
does almost count? (in this case)

i generally find it easier to read when things are split up like, including arithmetic where an intermediate value is a commonly named type of value. the variable name then documents what the code steps are coming up with.