Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use list unpacking #1

Open
cthoyt opened this issue Sep 8, 2017 · 2 comments
Open

Use list unpacking #1

cthoyt opened this issue Sep 8, 2017 · 2 comments

Comments

@cthoyt
Copy link

cthoyt commented Sep 8, 2017

There are a lot of places where you're getting sequential elements from a list. Use unpacking to make this code more readable:

MEN2017/miscellaneous.py

Lines 74 to 75 in 1f77631

q_p = predictionListStats[0]
q_m = predictionListStats[1]

At best, this can look like:

q_p,  q_m = predictionListStats

If there are more elements in predictionListStats, then you have a couple options:

Explicit assignment

q_p,  q_m = predictionListStats[0], predictionListStats[1] 

Unpacking sliced list

q_p,  q_m = predictionListStats[0:2]

Splat Unpacking

q_p,  q_m, *_ = predictionListStats
@ddomingof
Copy link
Member

Students where translating code from R to Python so they use the BEAUTIFUL R syntax.
I will try to implement this next week and send them the comments
Thanks for the advise 👍

@cthoyt
Copy link
Author

cthoyt commented Sep 8, 2017

Wow... I was going to say there's a lot of room for code clean up. I'll add more comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants