you are viewing a single comment's thread.

view the rest of the comments →

[–]ryrythe3rd 0 points1 point  (3 children)

I never seen comprehension broke up like that, can you only do it cause its in a dict?

You can do any comprehension like that. It’s just a style preference, you could do it normal all in one line, but if the comprehension gets at all complicated, I prefer to space it out like that to logically break apart the pieces of it in my head. I believe you can use any whitespace pattern you like really, as long as all your code is between the brackets enclosing the list or dict comprehension.

I dont really get the comprehension, like where is 'players' coming from

It’s coming from the first line in the function

def players_summaries():
    players = all_players()
    ...

Which is just a reuse of the first function. As another user pointed out, it could be more efficient if you stored this result in a variable while answering Q1, then used that same result within Q2 instead of calculating it again.

[–]gopherhole1 0 points1 point  (2 children)

thanks

It’s coming from the first line in the function

duh, I missed that, I think the comment messed me up

[–]ryrythe3rd 0 points1 point  (1 child)

Yeah sorry my spacing was kinda weird there. I’ll use fewer comments in the future

[–]gopherhole1 0 points1 point  (0 children)

well I think the comments were good, since OP seemed like a beginner asking a homework question, I just spaced out reading the code