-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored development branch #2
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: development
Are you sure you want to change the base?
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
print("Creating " + file_name + "in java and python dir...") | ||
with open("python/" + file_name + ".py", 'w'): | ||
print(f"Creating {file_name}in java and python dir...") | ||
with open(f"python/{file_name}.py", 'w'): | ||
pass | ||
with open("java/" + file_name + ".java", 'w'): | ||
with open(f"java/{file_name}.java", 'w'): |
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 9-12
refactored with the following changes:
- Use f-string instead of string concatenation [×6] (
use-fstring-for-concatenation
)
temp_s = '#'.join('{}'.format(s)) | ||
temp_s = '#'.join(f'{s}') |
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.
Function Solution.longestPalindrome
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
flag = True if x < 0 else False | ||
flag = x < 0 | ||
if flag: | ||
x = -x | ||
x = str(x)[::-1] | ||
|
||
if flag: | ||
x = "-" + x | ||
x = f"-{x}" | ||
|
||
value = 2 ** 31 | ||
x = int(x) | ||
if -value <= x < value: | ||
return x | ||
return 0 | ||
return x if -value <= x < value else 0 |
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.
Function Solution.reverse
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if pos < ls and str[pos] == '-': | ||
sign = -1 | ||
pos += 1 | ||
elif pos < ls and str[pos] == '+': | ||
pos += 1 | ||
if pos < ls: | ||
if str[pos] == '-': | ||
sign = -1 | ||
pos += 1 | ||
elif str[pos] == '+': | ||
pos += 1 | ||
while pos < ls and ord(str[pos]) >= ord('0') and ord(str[pos]) <= ord('9'): | ||
num = ord(str[pos]) - ord('0') | ||
if result > max_int / 10 or ( result == max_int / 10 and num >= 8): | ||
if sign == -1: | ||
return min_int | ||
return max_int | ||
return min_int if sign == -1 else max_int |
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.
Function Solution.myAtoi
refactored with the following changes:
- Lift repeated conditional into its own if statement (
lift-duplicated-conditional
) - Swap positions of nested conditionals (
swap-nested-ifs
) - Lift code into else after jump in control flow (
reintroduce-else
) - Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if
) - Replace if statement with if expression (
assign-if-exp
)
if (x == x[::-1]): | ||
return True | ||
return False | ||
return x == x[::-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.
Function Solution.isPalindrome
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
for j in range(i + 1, ls): | ||
# append ascending order pair | ||
if nums[i] < nums[j]: | ||
pair.append([i,j]) | ||
pair.extend([i,j] for j in range(i + 1, ls) if nums[i] < nums[j]) | ||
pos = 0 | ||
if len(pair) > 0: | ||
if pair: |
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.
Function Solution.nextPermutation
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
) - Simplify sequence length comparison (
simplify-len-comparison
)
This removes the following comments ( why? ):
# append ascending order pair
else: | ||
if len(stack) > 0: | ||
data[i] = 1 | ||
data[stack.pop(-1)] = 1 | ||
elif stack: | ||
data[i] = 1 | ||
data[stack.pop(-1)] = 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.
Function Solution.longestValidParentheses
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Simplify sequence length comparison (
simplify-len-comparison
)
l, r = int(0), len(nums) - 1 | ||
l, r = 0, len(nums) - 1 | ||
while l < r: | ||
mid = int((l + r) / 2) | ||
if nums[mid] < target: | ||
l = mid + 1 | ||
else: | ||
r = mid | ||
if nums[l] < target: | ||
return l + 1 | ||
return l | ||
return l + 1 if nums[l] < target else l |
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.
Function Solution.searchInsert
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
for j in range(9): | ||
if board[i][j] == '.': | ||
empty.append(9 * i + j) | ||
empty.extend(9 * i + j for j in range(9) if board[i][j] == '.') |
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.
Function Solution.solveSudoku
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
step = 0 | ||
for index in range(start + 1, end): | ||
if height[index] > 0: | ||
step += height[index] | ||
step = sum( | ||
height[index] for index in range(start + 1, end) if height[index] > 0 | ||
) |
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.
Function Solution.rain_water
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
)
Branch
development
refactored 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
development
branch, then run:Help us improve this pull request!