which is more Pythonic? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: which is more Pythonic? (/thread-19796.html) |
which is more Pythonic? - Skaperen - Jul-15-2019 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? RE: which is more Pythonic? - DeaD_EyE - Jul-15-2019 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. RE: which is more Pythonic? - metulburr - Jul-15-2019 i would say the first one slightly more readable as well RE: which is more Pythonic? - Skaperen - Jul-15-2019 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) ... RE: which is more Pythonic? - metulburr - Jul-15-2019 Its almost always easier to read when you split it up like in the first example. RE: which is more Pythonic? - Skaperen - Jul-16-2019 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. |