Typos in comments in hill_climbing.py (#1667)

* Typos in comments in hill_climbing.py

* fixup! Format Python code with psf/black push
This commit is contained in:
Christian Clauss 2020-01-08 14:06:53 +01:00 committed by John Law
parent 36d229f82a
commit 1f2b1a88ab
3 changed files with 41 additions and 35 deletions

View File

@ -7,17 +7,22 @@ Operations:
4. remove from the end -> O(1)
"""
class _DoublyLinkedBase:
""" A Private class (to be inherited) """
class _Node:
__slots__ = '_prev', '_data', '_next'
__slots__ = "_prev", "_data", "_next"
def __init__(self, link_p, element, link_n):
self._prev = link_p
self._data = element
self._next = link_n
def has_next_and_prev(self):
return " Prev -> {0}, Next -> {1}".format(self._prev != None, self._next != None)
return " Prev -> {0}, Next -> {1}".format(
self._prev != None, self._next != None
)
def __init__(self):
self._header = self._Node(None, None, None)
@ -53,8 +58,8 @@ class _DoublyLinkedBase:
del node
return temp
class LinkedDeque(_DoublyLinkedBase):
class LinkedDeque(_DoublyLinkedBase):
def first(self):
""" return first element
>>> d = LinkedDeque()
@ -64,7 +69,7 @@ class LinkedDeque(_DoublyLinkedBase):
'B'
"""
if self.is_empty():
raise Exception('List is empty')
raise Exception("List is empty")
return self._header._next._data
def last(self):
@ -76,7 +81,7 @@ class LinkedDeque(_DoublyLinkedBase):
'B'
"""
if self.is_empty():
raise Exception('List is empty')
raise Exception("List is empty")
return self._trailer._prev._data
### DEque Insert Operations (At the front, At the end) ###
@ -114,7 +119,7 @@ class LinkedDeque(_DoublyLinkedBase):
True
"""
if self.is_empty():
raise IndexError('remove_first from empty list')
raise IndexError("remove_first from empty list")
return self._delete(self._header._next)
def remove_last(self):
@ -134,5 +139,5 @@ class LinkedDeque(_DoublyLinkedBase):
True
"""
if self.is_empty():
raise IndexError('remove_first from empty list')
raise IndexError("remove_first from empty list")
return self._delete(self._trailer._prev)

View File

@ -23,7 +23,7 @@ class SearchProblem:
def score(self) -> int:
"""
Returns the output for the function called with current x and y coordinates.
Returns the output of the function called with current x and y coordinates.
>>> def test_function(x, y):
... return x + y
>>> SearchProblem(0, 0, 1, test_function).score() # 0 + 0 = 0
@ -91,7 +91,7 @@ def hill_climbing(
have any neighbors which can improve the solution.
Args:
search_prob: The search state at the start.
find_max: If True, the algorithm should find the minimum else the minimum.
find_max: If True, the algorithm should find the maximum else the minimum.
max_x, min_x, max_y, min_y: the maximum and minimum bounds of x and y.
visualization: If True, a matplotlib graph is displayed.
max_iter: number of times to run the iteration.

View File

@ -26,15 +26,16 @@ def bubble_sort(list1):
for i, num in enumerate(list1):
try:
if list1[i+1] < num:
list1[i] = list1[i+1]
list1[i+1] = num
if list1[i + 1] < num:
list1[i] = list1[i + 1]
list1[i + 1] = num
bubble_sort(list1)
except IndexError:
pass
return list1
if __name__ == "__main__":
list1 = [33,99,22,11,66]
list1 = [33, 99, 22, 11, 66]
bubble_sort(list1)
print(list1)