-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,7 @@ | |
| # coding=utf-8 | ||
|
|
||
| def count_substring(string, sub_string): | ||
| count = 0 | ||
| for i in range(len(string)): | ||
| if string[i:].startswith(sub_string): | ||
| count += 1 | ||
| return count | ||
| return sum(bool(string[i:].startswith(sub_string)) for i in range(len(string))) | ||
|
Author
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. Function
|
||
|
|
||
| if __name__ == '__main__': | ||
| string = input().strip() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,5 @@ | |
| n = int(input()) | ||
| arr = map(int, input().split()) | ||
|
|
||
| # remove duplicates | ||
| arr = list(dict.fromkeys(arr)) | ||
| # sort | ||
| arr.sort() | ||
|
|
||
| arr = sorted(dict.fromkeys(arr)) | ||
|
Author
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. Lines
This removes the following comments ( why? ): |
||
| print(arr[-2]) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,9 @@ | ||
| #!/usr/bin/env python | ||
| # coding=utf-8 | ||
|
|
||
| scores_stats = [] | ||
|
|
||
| for _ in range(0,int(input())): | ||
| scores_stats.append([input(), float(input())]) | ||
|
|
||
| scores_stats = [[input(), float(input())] for _ in range(int(input()))] | ||
| # Make a unique list of score, sort it and get the lowest second score | ||
| second_lowest = sorted(list(set([score for name, score in scores_stats])))[1] | ||
| second_lowest = sorted(list({score for name, score in scores_stats}))[1] | ||
|
Comment on lines
-4
to
+6
Author
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. Lines
|
||
|
|
||
| # Iterate over the list of scores and names and print every match to the | ||
| # lowest score we got above | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,7 @@ def before_refactor(): | |
|
|
||
| mushrooms = [Mushroom('Portabello', False), Mushroom('Oyster', False), | ||
| Mushroom('Death Cap', True)] | ||
| i = 0 | ||
|
|
||
| for mushroom in mushrooms: | ||
| i += 1 | ||
| for i, mushroom in enumerate(mushrooms, start=1): | ||
|
Author
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. Function
|
||
| name = mushroom.name | ||
| print('%d:"%s"' % (i, name)) | ||
|
|
||
|
|
||
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.
Lines
11-19refactored with the following changes:withwhen opening file to ensure closure (ensure-file-closed)