Skip to content

Commit

Permalink
fixup! Format Python code with psf/black push
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions authored and github-actions committed May 3, 2020
1 parent 01e48e8 commit 2ff7bc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 9 additions & 4 deletions data_structures/binary_tree/segment_tree_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, start, end, val, left=None, right=None):
self.right = right

def __str__(self):
return 'val: %s, start: %s, end: %s' % (self.val, self.start, self.end)
return "val: %s, start: %s, end: %s" % (self.val, self.start, self.end)


class SegmentTree(object):
Expand Down Expand Up @@ -131,6 +131,7 @@ class SegmentTree(object):
>>>
"""

def __init__(self, collection: Sequence, function):
self.collection = collection
self.fn = function
Expand Down Expand Up @@ -197,7 +198,10 @@ def _query_range(self, node, i, j):
return self._query_range(node.left, i, j)
else:
# range in left child tree and right child tree
return self.fn(self._query_range(node.left, i, node.mid), self._query_range(node.right, node.mid + 1, j))
return self.fn(
self._query_range(node.left, i, node.mid),
self._query_range(node.right, node.mid + 1, j),
)
else:
# range in right child tree
return self._query_range(node.right, i, j)
Expand All @@ -217,10 +221,11 @@ def traverse(self):
queue.put(node.right)


if __name__ == '__main__':
if __name__ == "__main__":
import operator

for fn in [operator.add, max, min]:
print('*' * 50)
print("*" * 50)
arr = SegmentTree([2, 1, 5, 3, 4], fn)
for node in arr.traverse():
print(node)
Expand Down
5 changes: 2 additions & 3 deletions data_structures/stacks/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def is_empty(self):
def size(self):
""" Return the size of the stack."""
return len(self.stack)

def __contains__(self, item) -> bool:
"""Check if item is in stack"""
return item in self.stack


class StackOverflowError(BaseException):
pass
Expand All @@ -73,4 +73,3 @@ class StackOverflowError(BaseException):
num = 5
if num in stack:
print(f"{num} is in stack")

0 comments on commit 2ff7bc2

Please sign in to comment.