Skip to content

Fix typos in Sorts and Bit_manipulation #4949

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

Merged
merged 3 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions bit_manipulation/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations
https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations
https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types

https://wiki.python.org/moin/BitManipulation
https://wiki.python.org/moin/BitwiseOperators
https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
* https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations
* https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations
* https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types
* https://wiki.python.org/moin/BitManipulation
* https://wiki.python.org/moin/BitwiseOperators
* https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
4 changes: 2 additions & 2 deletions bit_manipulation/binary_and_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def binary_and(a: int, b: int) -> str:
>>> binary_and(0, -1)
Traceback (most recent call last):
...
ValueError: the value of both input must be positive
ValueError: the value of both inputs must be positive
>>> binary_and(0, 1.1)
Traceback (most recent call last):
...
Expand All @@ -33,7 +33,7 @@ def binary_and(a: int, b: int) -> str:
TypeError: '<' not supported between instances of 'str' and 'int'
"""
if a < 0 or b < 0:
raise ValueError("the value of both input must be positive")
raise ValueError("the value of both inputs must be positive")

a_binary = str(bin(a))[2:] # remove the leading "0b"
b_binary = str(bin(b))[2:] # remove the leading "0b"
Expand Down
4 changes: 2 additions & 2 deletions bit_manipulation/binary_or_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def binary_or(a: int, b: int) -> str:
>>> binary_or(0, -1)
Traceback (most recent call last):
...
ValueError: the value of both input must be positive
ValueError: the value of both inputs must be positive
>>> binary_or(0, 1.1)
Traceback (most recent call last):
...
Expand All @@ -32,7 +32,7 @@ def binary_or(a: int, b: int) -> str:
TypeError: '<' not supported between instances of 'str' and 'int'
"""
if a < 0 or b < 0:
raise ValueError("the value of both input must be positive")
raise ValueError("the value of both inputs must be positive")
a_binary = str(bin(a))[2:] # remove the leading "0b"
b_binary = str(bin(b))[2:]
max_len = max(len(a_binary), len(b_binary))
Expand Down
4 changes: 2 additions & 2 deletions bit_manipulation/binary_xor_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def binary_xor(a: int, b: int) -> str:
>>> binary_xor(0, -1)
Traceback (most recent call last):
...
ValueError: the value of both input must be positive
ValueError: the value of both inputs must be positive
>>> binary_xor(0, 1.1)
Traceback (most recent call last):
...
Expand All @@ -33,7 +33,7 @@ def binary_xor(a: int, b: int) -> str:
TypeError: '<' not supported between instances of 'str' and 'int'
"""
if a < 0 or b < 0:
raise ValueError("the value of both input must be positive")
raise ValueError("the value of both inputs must be positive")

a_binary = str(bin(a))[2:] # remove the leading "0b"
b_binary = str(bin(b))[2:] # remove the leading "0b"
Expand Down
8 changes: 4 additions & 4 deletions sorts/bead_sort.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Bead sort only works for sequences of nonegative integers.
Bead sort only works for sequences of non-negative integers.
https://en.wikipedia.org/wiki/Bead_sort
"""

Expand All @@ -21,15 +21,15 @@ def bead_sort(sequence: list) -> list:
>>> bead_sort([1, .9, 0.0, 0, -1, -.9])
Traceback (most recent call last):
...
TypeError: Sequence must be list of nonnegative integers
TypeError: Sequence must be list of non-negative integers

>>> bead_sort("Hello world")
Traceback (most recent call last):
...
TypeError: Sequence must be list of nonnegative integers
TypeError: Sequence must be list of non-negative integers
"""
if any(not isinstance(x, int) or x < 0 for x in sequence):
raise TypeError("Sequence must be list of nonnegative integers")
raise TypeError("Sequence must be list of non-negative integers")
for _ in range(len(sequence)):
for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])):
if rod_upper > rod_lower:
Expand Down
6 changes: 3 additions & 3 deletions sorts/double_sort.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def double_sort(lst):
"""this sorting algorithm sorts an array using the principle of bubble sort,
but does it both from left to right and right to left,
hence i decided to call it "double sort"
"""This sorting algorithm sorts an array using the principle of bubble sort,
but does it both from left to right and right to left.
Hence, it's called "Double sort"
:param collection: mutable ordered sequence of elements
:return: the same collection in ascending order
Examples:
Expand Down