mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Fix typos in Sorts and Bit_manipulation (#4949)
* Fix several typos * Update bit_manipulation/README.md Co-authored-by: John Law <johnlaw.po@gmail.com> * Update double_sort.py Co-authored-by: John Law <johnlaw.po@gmail.com>
This commit is contained in:
parent
83cf5786cd
commit
50485f7c8e
|
@ -1,7 +1,6 @@
|
||||||
https://docs.python.org/3/reference/expressions.html#binary-bitwise-operations
|
* 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/reference/expressions.html#unary-arithmetic-and-bitwise-operations
|
||||||
https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types
|
* https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types
|
||||||
|
* https://wiki.python.org/moin/BitManipulation
|
||||||
https://wiki.python.org/moin/BitManipulation
|
* https://wiki.python.org/moin/BitwiseOperators
|
||||||
https://wiki.python.org/moin/BitwiseOperators
|
* https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
||||||
https://www.tutorialspoint.com/python3/bitwise_operators_example.htm
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ def binary_and(a: int, b: int) -> str:
|
||||||
>>> binary_and(0, -1)
|
>>> binary_and(0, -1)
|
||||||
Traceback (most recent call last):
|
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)
|
>>> binary_and(0, 1.1)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
|
@ -33,7 +33,7 @@ def binary_and(a: int, b: int) -> str:
|
||||||
TypeError: '<' not supported between instances of 'str' and 'int'
|
TypeError: '<' not supported between instances of 'str' and 'int'
|
||||||
"""
|
"""
|
||||||
if a < 0 or b < 0:
|
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"
|
a_binary = str(bin(a))[2:] # remove the leading "0b"
|
||||||
b_binary = str(bin(b))[2:] # remove the leading "0b"
|
b_binary = str(bin(b))[2:] # remove the leading "0b"
|
||||||
|
|
|
@ -21,7 +21,7 @@ def binary_or(a: int, b: int) -> str:
|
||||||
>>> binary_or(0, -1)
|
>>> binary_or(0, -1)
|
||||||
Traceback (most recent call last):
|
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)
|
>>> binary_or(0, 1.1)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
|
@ -32,7 +32,7 @@ def binary_or(a: int, b: int) -> str:
|
||||||
TypeError: '<' not supported between instances of 'str' and 'int'
|
TypeError: '<' not supported between instances of 'str' and 'int'
|
||||||
"""
|
"""
|
||||||
if a < 0 or b < 0:
|
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"
|
a_binary = str(bin(a))[2:] # remove the leading "0b"
|
||||||
b_binary = str(bin(b))[2:]
|
b_binary = str(bin(b))[2:]
|
||||||
max_len = max(len(a_binary), len(b_binary))
|
max_len = max(len(a_binary), len(b_binary))
|
||||||
|
|
|
@ -22,7 +22,7 @@ def binary_xor(a: int, b: int) -> str:
|
||||||
>>> binary_xor(0, -1)
|
>>> binary_xor(0, -1)
|
||||||
Traceback (most recent call last):
|
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)
|
>>> binary_xor(0, 1.1)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
|
@ -33,7 +33,7 @@ def binary_xor(a: int, b: int) -> str:
|
||||||
TypeError: '<' not supported between instances of 'str' and 'int'
|
TypeError: '<' not supported between instances of 'str' and 'int'
|
||||||
"""
|
"""
|
||||||
if a < 0 or b < 0:
|
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"
|
a_binary = str(bin(a))[2:] # remove the leading "0b"
|
||||||
b_binary = str(bin(b))[2:] # remove the leading "0b"
|
b_binary = str(bin(b))[2:] # remove the leading "0b"
|
||||||
|
|
|
@ -21,15 +21,15 @@ def bead_sort(sequence: list) -> list:
|
||||||
>>> bead_sort([1, .9, 0.0, 0, -1, -.9])
|
>>> bead_sort([1, .9, 0.0, 0, -1, -.9])
|
||||||
Traceback (most recent call last):
|
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")
|
>>> bead_sort("Hello world")
|
||||||
Traceback (most recent call last):
|
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):
|
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 _ in range(len(sequence)):
|
||||||
for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])):
|
for i, (rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])):
|
||||||
if rod_upper > rod_lower:
|
if rod_upper > rod_lower:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
def double_sort(lst):
|
def double_sort(lst):
|
||||||
"""this sorting algorithm sorts an array using the principle of bubble 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,
|
but does it both from left to right and right to left.
|
||||||
hence i decided to call it "double sort"
|
Hence, it's called "Double sort"
|
||||||
:param collection: mutable ordered sequence of elements
|
:param collection: mutable ordered sequence of elements
|
||||||
:return: the same collection in ascending order
|
:return: the same collection in ascending order
|
||||||
Examples:
|
Examples:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user