-
Notifications
You must be signed in to change notification settings - Fork 162
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
challenge 7 in python
- Loading branch information
commit ccd15a08b81b7bcaab646dee7c1d58d03deb7459
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def missing_int(L): | ||
|
||
sum_n = 0 | ||
sum_n_less_1 = 0 | ||
|
||
for i in range(len(L)+1): | ||
sum_n += i | ||
|
||
for i in L: | ||
sum_n_less_1 += i | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try the more pythonic and readable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, thanks, didn't know it existed :) |
||
|
||
return sum_n - sum_n_less_1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# we start by importing the unittest module | ||
import unittest | ||
|
||
# Next lets import our function that we intend to do testing on | ||
# | ||
# **We could also import all functions by using * or just import the module | ||
# itself but for now lets just import the function | ||
from challenge_7 import missing_int | ||
|
||
# lets define our suite of tests as a class and lets inherit from unittest.TestCase | ||
class TestBinaryMethods(unittest.TestCase): | ||
|
||
def test_missingInt(self): | ||
""" Tests from the READ.me """ | ||
|
||
self.assertEqual(missing_int([1,3,4,0]), 2) | ||
self.assertEqual(missing_int([1,2,3]), 0) | ||
self.assertEqual(missing_int([0,1,2,4]), 3) | ||
|
||
# if the python file is ran by itself run unittest | ||
# This allows us to import the members of the file without running main if we need to | ||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)])
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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