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

[Python] Challenge 7 (Unreviewed) #361

Merged
merged 5 commits into from
Jan 23, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using sum(L)
  • Loading branch information
sarcodian committed Jan 23, 2017
commit 88f77c9ab91f7e770b5d2a33f54f69ad5c6dcb58
3 changes: 1 addition & 2 deletions challenge_7/python/sarcodian/src/challenge_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def missing_int(L):
for i in range(len(L)+1):
sum_n += i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try the more pythonic sum([i for i in range(len(L)+1)])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can you provide a link or something that provides a deeper explanation of <i for i in range(len(L)+1)> syntax. I have seen it a lot in other code as well, but I don't get the logic behind how it works so I am wary of just using it. Or even if you provide the name for what that type of syntax is called I can google it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As sent to you in slack, here's a great video on the topic (and also for the reference of others)
https://www.youtube.com/watch?v=ZoWgzG_r2qo


for i in L:
sum_n_less_1 += i
sum_n_less_1 = sum(L)

return sum_n - sum_n_less_1

Expand Down