searches.double_linear_search_recursion¶
Classes¶
Base class for protocol classes. |
|
Functions¶
|
Iterate through the array to find the index of key using recursion. |
Module Contents¶
- class searches.double_linear_search_recursion.Comparable¶
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto[T](Protocol): def meth(self) -> T: ...
- __eq__(other: object) bool¶
- __gt__(other: Comparable) bool¶
- searches.double_linear_search_recursion.search[T: Comparable](list_data: list[T], key: T, left: int = 0, right: int = 0) int¶
Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched :param key: the key to be searched :param left: the index of first element :param right: the index of last element :return: the index of key value if found, -1 otherwise.
>>> search(list(range(0, 11)), 5) 5 >>> search([1, 2, 4, 5, 3], 4) 2 >>> search([1, 2, 4, 5, 3], 6) -1 >>> search([5], 5) 0 >>> search([], 1) -1 >>> search([Person("Al"), Person("Bob"), Person("Carl")], Person("Bob")) 1 >>> search([Person("Al"), Person("Bob"), Person("Carl")], "Bob") -1