mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-27 17:06:44 +00:00
Replace typing.optional with new annotations syntax (#5829)
* Replace typing.optional with new annotations syntax * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
d848bfbf32
commit
1ae5abfc3c
@ -525,6 +525,7 @@
|
|||||||
* [Perfect Cube](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_cube.py)
|
* [Perfect Cube](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_cube.py)
|
||||||
* [Perfect Number](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_number.py)
|
* [Perfect Number](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_number.py)
|
||||||
* [Perfect Square](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_square.py)
|
* [Perfect Square](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_square.py)
|
||||||
|
* [Persistence](https://github.com/TheAlgorithms/Python/blob/master/maths/persistence.py)
|
||||||
* [Pi Monte Carlo Estimation](https://github.com/TheAlgorithms/Python/blob/master/maths/pi_monte_carlo_estimation.py)
|
* [Pi Monte Carlo Estimation](https://github.com/TheAlgorithms/Python/blob/master/maths/pi_monte_carlo_estimation.py)
|
||||||
* [Pollard Rho](https://github.com/TheAlgorithms/Python/blob/master/maths/pollard_rho.py)
|
* [Pollard Rho](https://github.com/TheAlgorithms/Python/blob/master/maths/pollard_rho.py)
|
||||||
* [Polynomial Evaluation](https://github.com/TheAlgorithms/Python/blob/master/maths/polynomial_evaluation.py)
|
* [Polynomial Evaluation](https://github.com/TheAlgorithms/Python/blob/master/maths/polynomial_evaluation.py)
|
||||||
|
@ -5,8 +5,9 @@ Nodes contain data and also may link to other nodes:
|
|||||||
head node gives us access of the complete list
|
head node gives us access of the complete list
|
||||||
- Last node: points to null
|
- Last node: points to null
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
@ -17,7 +18,7 @@ class Node:
|
|||||||
|
|
||||||
class LinkedList:
|
class LinkedList:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.head: Optional[Node] = None
|
self.head: Node | None = None
|
||||||
self.size = 0
|
self.size = 0
|
||||||
|
|
||||||
def add(self, item: Any) -> None:
|
def add(self, item: Any) -> None:
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
from typing import Any, Iterator, Optional
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any, Iterator
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, data: Any):
|
def __init__(self, data: Any):
|
||||||
self.data: Any = data
|
self.data: Any = data
|
||||||
self.next: Optional[Node] = None
|
self.next: Node | None = None
|
||||||
|
|
||||||
|
|
||||||
class CircularLinkedList:
|
class CircularLinkedList:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
from typing import Any, Optional
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class ContainsLoopError(Exception):
|
class ContainsLoopError(Exception):
|
||||||
@ -8,7 +10,7 @@ class ContainsLoopError(Exception):
|
|||||||
class Node:
|
class Node:
|
||||||
def __init__(self, data: Any) -> None:
|
def __init__(self, data: Any) -> None:
|
||||||
self.data: Any = data
|
self.data: Any = data
|
||||||
self.next_node: Optional[Node] = None
|
self.next_node: Node | None = None
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
node = self
|
node = self
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Optional
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
@ -17,7 +17,7 @@ class LinkedList:
|
|||||||
self.head = new_node
|
self.head = new_node
|
||||||
return self.head.data
|
return self.head.data
|
||||||
|
|
||||||
def middle_element(self) -> Optional[int]:
|
def middle_element(self) -> int | None:
|
||||||
"""
|
"""
|
||||||
>>> link = LinkedList()
|
>>> link = LinkedList()
|
||||||
>>> link.middle_element()
|
>>> link.middle_element()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from math import gcd
|
from math import gcd
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
|
|
||||||
def pollard_rho(
|
def pollard_rho(
|
||||||
@ -7,7 +8,7 @@ def pollard_rho(
|
|||||||
seed: int = 2,
|
seed: int = 2,
|
||||||
step: int = 1,
|
step: int = 1,
|
||||||
attempts: int = 3,
|
attempts: int = 3,
|
||||||
) -> Union[int, None]:
|
) -> int | None:
|
||||||
"""
|
"""
|
||||||
Use Pollard's Rho algorithm to return a nontrivial factor of ``num``.
|
Use Pollard's Rho algorithm to return a nontrivial factor of ``num``.
|
||||||
The returned factor may be composite and require further factorization.
|
The returned factor may be composite and require further factorization.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user