Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Dec 14, 2023

Branch master 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from edson-github December 14, 2023 22:55
Copy link
Author

@sourcery-ai sourcery-ai bot left a 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.

Comment on lines 20 to 21
b = carry
if b > 0: return (a & mask)
else: return a No newline at end of file
return (a & mask) if b > 0 else a No newline at end of file
Copy link
Author

Choose a reason for hiding this comment

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

Function getSum refactored with the following changes:

# columns are the values of weights required

t = [[0 for i in range(cols)] for i in range(rows)]
t = [[0 for _ in range(cols)] for _ in range(rows)]
Copy link
Author

Choose a reason for hiding this comment

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

Function knapsack refactored with the following changes:

Comment on lines 20 to 26

if i + z[i] - 1 > r:
l = i
r = i + z[i] - 1

res = []
for i in range(size , len(text)):
if z[i] == size:
res.append(i - size - 1)
return res

return [i - size - 1 for i in range(size , len(text)) if z[i] == size]
Copy link
Author

Choose a reason for hiding this comment

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

Function Z_Algorithm.z_function refactored with the following changes:

rows = len(s2) + 1

t = [[0 for i in range(cols)] for i in range(rows)]
t = [[0 for _ in range(cols)] for _ in range(rows)]
Copy link
Author

Choose a reason for hiding this comment

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

Function lcs refactored with the following changes:

rows = len(s2) + 1

t = [[0 for i in range(cols)] for i in range(rows)]
t = [[0 for _ in range(cols)] for _ in range(rows)]
Copy link
Author

Choose a reason for hiding this comment

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

Function lcs refactored with the following changes:

result.append(i)

return result
return [i for i in range(1, n+1) if (n%i == 0)]
Copy link
Author

Choose a reason for hiding this comment

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

Function divisors.findAllDivisors refactored with the following changes:

Comment on lines -19 to +13
result = list()

for i in range(1, n+1):
if (n%i == 0 and i%2==1):
result.append(i)

return result
return [i for i in range(1, n+1) if (n%i == 0 and i%2==1)]
Copy link
Author

Choose a reason for hiding this comment

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

Function divisors.oddFactors refactored with the following changes:

Comment on lines -32 to +20
result = list()

for i in range(1, n+1):
if (n%i == 0 and i%2==0):
result.append(i)

return result
return [i for i in range(1, n+1) if (n%i == 0 and i%2==0)]
Copy link
Author

Choose a reason for hiding this comment

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

Function divisors.evenFactors refactored with the following changes:

Comment on lines -45 to +27
result = list()
result = []
Copy link
Author

Choose a reason for hiding this comment

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

Function divisors.primeFactors refactored with the following changes:

Comment on lines -9 to +10
else:
for num in range(1, number+1):
answer = answer * num
for num in range(1, number+1):
answer = answer * num
Copy link
Author

Choose a reason for hiding this comment

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

Function factorial refactored with the following changes:

answer = number * factorial(number - 1)

return answer
return 1 if number in [0, 1] else number * factorial(number - 1)
Copy link
Author

Choose a reason for hiding this comment

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

Function factorial refactored with the following changes:

return x

return gcd(y, x % y)
return x if y == 0 else gcd(y, x % y)
Copy link
Author

Choose a reason for hiding this comment

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

Function gcd refactored with the following changes:

return bases[x]
else:
return default
return bases[x] if x in bases else default
Copy link
Author

Choose a reason for hiding this comment

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

Function verify_base refactored with the following changes:

if(negative):
decimal_number = '-' + decimal_number
if negative:
decimal_number = f'-{decimal_number}'
Copy link
Author

Choose a reason for hiding this comment

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

Function convert refactored with the following changes:

Comment on lines -11 to +13
while i * i < num:
while i**2 < num:
i += 1
if i * i == num:
return True
else:
return False
return i**2 == num
Copy link
Author

Choose a reason for hiding this comment

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

Function is_perfect_square refactored with the following changes:

else:
return "Not found"

return "Found" if arr[0] == val else "Not found"
Copy link
Author

Choose a reason for hiding this comment

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

Function search refactored with the following changes:

Comment on lines -9 to +10
else:
if arr[i] < arr[i-1]:
arr[i-1], arr[i] = arr[i], arr[i-1]
elif arr[i] < arr[i-1]:
arr[i-1], arr[i] = arr[i], arr[i-1]
Copy link
Author

Choose a reason for hiding this comment

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

Function rearrange refactored with the following changes:

start = 0
n = len(arr) - 1

Copy link
Author

Choose a reason for hiding this comment

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

Function find_sum refactored with the following changes:

Comment on lines -11 to +17
checker = 0
pos = 0
checker = 0
for i in s:
val = ord(i) - ord('a')
if (checker & (1 << val) > 0):
return i
checker = checker | (1 << val)
pos += 1
else:
checker = checker | (1 << val)
Copy link
Author

Choose a reason for hiding this comment

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

Function first_recurrence refactored with the following changes:

return min_pos

if count_negative & 1 == 0 and count_negative != 0:
if count_negative & 1 == 0:
Copy link
Author

Choose a reason for hiding this comment

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

Function find refactored with the following changes:

Comment on lines -4 to +5
# First find out how many elements are there which are less than or
# equal to k
count = 0
for i in arr:
if i <= k:
count += 1

# This count defines a window - inside this window all our elements should
# be placed
# Find the count of bad elements - elements which are more than k and that will be
# our starting answer as we will have to swap them out
bad = 0
for i in range(0, count):
if arr[i] > k:
bad += 1

count = sum(1 for i in arr if i <= k)
bad = sum(1 for i in range(0, count) if arr[i] > k)
Copy link
Author

Choose a reason for hiding this comment

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

Function min_swaps refactored with the following changes:

This removes the following comments ( why? ):

# This count defines a window - inside this window all our elements should
# First find out how many elements are there which are less than or
# our starting answer as we will have to swap them out
# equal to k
# Find the count of bad elements - elements which are more than k and that will be
# be placed

count = 0
for a in arr:
if not a == 0:
if a != 0:
Copy link
Author

Choose a reason for hiding this comment

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

Function move refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

def partition(arr):
s = sum(arr)
if not s % 3 == 0:
if s % 3 != 0:
Copy link
Author

Choose a reason for hiding this comment

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

Function partition refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

rem_lst = lst[:i] + lst[i+1:]
for p in permutation(rem_lst):
l.append([m] + p)
l.extend([m] + p for p in permutation(rem_lst))
Copy link
Author

Choose a reason for hiding this comment

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

Function permutation refactored with the following changes:

Comment on lines -15 to +18
else:
pivot = array[0]
less = [i for i in array[1:] if i <= pivot]
greater = [i for i in array[1:] if i > pivot]
return quicksort(less) + [pivot] + quicksort(greater)
pivot = array[0]
less = [i for i in array[1:] if i <= pivot]
greater = [i for i in array[1:] if i > pivot]
return quicksort(less) + [pivot] + quicksort(greater)
Copy link
Author

Choose a reason for hiding this comment

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

Function quicksort refactored with the following changes:

Comment on lines -17 to +22
if root.left == None and root.right == None and root.val == arr[index] and index == n -1:
if (
root.left is None
and root.right is None
and root.val == arr[index]
and index == n - 1
):
Copy link
Author

Choose a reason for hiding this comment

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

Function check_path refactored with the following changes:

Comment on lines -15 to +26
if not root or (not root.left and not root.right):
if not root or not root.left and not root.right:
return True

else:
if root.left:
l = root.left.val
if root.left:
l = root.left.val

if root.right:
r = root.right.val
if root.right:
r = root.right.val

if (root.val == l + r) and sum_prop(root.left) and sum_prop(root.right):
return True
else:
return False
return bool(
(root.val == l + r) and sum_prop(root.left) and sum_prop(root.right)
)
Copy link
Author

Choose a reason for hiding this comment

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

Function sum_prop refactored with the following changes:

Comment on lines -22 to +29

if root.left == None and root.right == None:
return True

if root.left == None:
if root.left is None:
if root.right is None:
return True

return (abs(root.val - root.right.val) == 1) and continuous(root.right)

if root.right == None:
if root.right is None:
Copy link
Author

Choose a reason for hiding this comment

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

Function continuous refactored with the following changes:

Comment on lines -34 to +36
for i in diagonal_map:
for j in diagonal_map[i]:

for value in diagonal_map.values():
for j in value:
Copy link
Author

Choose a reason for hiding this comment

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

Function diagonal_print refactored with the following changes:

Comment on lines -19 to +22
else:
lheight = height(root.left)
rheight = height(root.right)
lheight = height(root.left)
rheight = height(root.right)

return 1 + max(lheight, rheight)
return 1 + max(lheight, rheight)
Copy link
Author

Choose a reason for hiding this comment

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

Function height refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant