Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 which is more Pythonic?
#1
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?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#2
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.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Quote
#3
i would say the first one slightly more readable as well
Quote
#4
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)
...
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#5
Its almost always easier to read when you split it up like in the first example.
Quote
#6
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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  which is "better" (or more Pythonic)? Skaperen 8 287 Nov-16-2019, 06:46 PM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)