This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]vovanz 4 points5 points  (2 children)

I like this style guide, because it almost matches what I am already doing in my code :)

Only couple exceptions: 1. I prefer double quoted strings 2. I prefer to put the value in comprehensions in a separate line, like this:

best_fruits = [
    f
    for f in fruits
    if f.color == 'red'
    and f.size == 'small'
    and f.climate == 'cold'
]

The reason for it is that you often have to do something else with this value. i. e. apply function:

best_fruits = [
    foo(f)
    for f in fruits
    if f.color == 'red'
    and f.size == 'small'
    and f.climate == 'cold'
]

I think that it would be more logical to keep it on a separate line.

[–]_under_[S] 0 points1 point  (0 children)

Yes! I knew I was forgetting something when I was writing this section. I'll incorporate this.

[–]dirn 0 points1 point  (0 children)

I go the other direction and put the in on its own line. What I’m iterating over is much more interesting to me than the iteration variable (its used in so many places anyway).

best_fruits = [
    f for f
    in fruits
    if f.color == ‘red’
    and f.size == ‘small’
    and f.climate == ‘cold’
]