From 69b077a3b1643432d6c813c2ef4190cf481214be Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 12 Apr 2020 17:13:15 +0200 Subject: [PATCH 1/2] README.md: sumab() --> sum_ab() for consistancy consistency --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2aa4be9e5324..39d67c240e85 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,7 +82,7 @@ We want your work to be readable by others; therefore, we encourage you to note ```python def sum_ab(a, b): """ - Returns the sum of two integers a and b + Return the sum of two integers a and b >>> sum_ab(2, 2) 4 >>> sum_ab(-2, 3) @@ -116,8 +116,8 @@ We want your work to be readable by others; therefore, we encourage you to note The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission. ```python - def sumab(a: int, b: int) --> int: - pass + def sum_ab(a: int, b: int) --> int: + return a + b ``` - [__List comprehensions and generators__](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions) are preferred over the use of `lambda`, `map`, `filter`, `reduce` but the important thing is to demonstrate the power of Python in code that is easy to read and maintain. From 6f097af35b0a031b79afcccb35182f5cd79776f1 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 12 Apr 2020 15:13:48 +0000 Subject: [PATCH 2/2] fixup! Format Python code with psf/black push --- .../linked_list/middle_element_of_linked_list.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data_structures/linked_list/middle_element_of_linked_list.py b/data_structures/linked_list/middle_element_of_linked_list.py index 2903fe604dfa..b845d2f19c20 100644 --- a/data_structures/linked_list/middle_element_of_linked_list.py +++ b/data_structures/linked_list/middle_element_of_linked_list.py @@ -8,14 +8,14 @@ class LinkedList: def __init__(self): self.head = None - def push(self, new_data:int) -> int: - new_node = Node(new_data) - new_node.next = self.head + def push(self, new_data: int) -> int: + new_node = Node(new_data) + new_node.next = self.head self.head = new_node return self.head.data def middle_element(self) -> int: - ''' + """ >>> link = LinkedList() >>> link.middle_element() No element found. @@ -44,11 +44,11 @@ def middle_element(self) -> int: >>> link.middle_element() 12 >>> - ''' + """ slow_pointer = self.head fast_pointer = self.head - if self.head: - while fast_pointer and fast_pointer.next: + if self.head: + while fast_pointer and fast_pointer.next: fast_pointer = fast_pointer.next.next slow_pointer = slow_pointer.next return slow_pointer.data