Open
Conversation
Comment on lines
-11
to
+16
| fptr = open(os.environ['OUTPUT_PATH'], 'w') | ||
| with open(os.environ['OUTPUT_PATH'], 'w') as fptr: | ||
| s = input() | ||
|
|
||
| s = input() | ||
| result = solve(s) | ||
|
|
||
| result = solve(s) | ||
|
|
||
| fptr.write(result + '\n') | ||
|
|
||
| fptr.close() | ||
| fptr.write(result + '\n') |
Author
There was a problem hiding this comment.
Lines 11-19 refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| 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.
Function count_substring refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension) - Simplify constant sum() call (
simplify-constant-sum) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| # sort | ||
| arr.sort() | ||
|
|
||
| arr = sorted(dict.fromkeys(arr)) |
Author
There was a problem hiding this comment.
Lines 8-12 refactored with the following changes:
- Remove an unnecessary list construction call prior to sorting (
skip-sorted-list-construction)
This removes the following comments ( why? ):
# sort
# remove duplicates
Comment on lines
-4
to
+6
| 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] |
Author
There was a problem hiding this comment.
Lines 4-10 refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Replace range(0, x) with range(x) (
remove-zero-from-range) - Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension) - Replace unneeded comprehension with generator (
comprehension-to-generator)
|
|
||
| for mushroom in mushrooms: | ||
| i += 1 | ||
| for i, mushroom in enumerate(mushrooms, start=1): |
Author
There was a problem hiding this comment.
Function before_refactor refactored with the following changes:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!