trendlist.trendlist.TrendList
- class trendlist.trendlist.TrendList(s: Optional[Iterable[Union[float, int, trendlist.trendlist.Trend]]] = None, reverse: bool = False)
Bases:
list
A list of trends.
Note that this sub-classes list.
- __init__(s: Optional[Iterable[Union[float, int, trendlist.trendlist.Trend]]] = None, reverse: bool = False) None
Initialize Trend object.
- Args:
s: A list of either numbers or of Trend objects reverse: Create a decreasing trend
Methods
__init__
([s, reverse])Initialize Trend object.
append
(other)Append a new trend, in-place.
clear
()Remove all items from list.
copy
()Return a shallow copy of the list.
count
(value, /)Return number of occurrences of value.
extend
(iterable, /)Extend list by appending elements from the iterable.
index
(value[, start, stop])Return first index of value.
insert
(index, object, /)Insert object before index.
pop
([index])Remove and return item at index (default last).
remove
(value, /)Remove first occurrence of value.
reverse
()Reverse IN PLACE.
rotate
()Move the leftmost trend to the right end, then merge.
single
()Rotate until there's a single trend.
sort
(*[, key, reverse])Sort the list in ascending order and return None.
- append(other: trendlist.trendlist.Trend) None
Append a new trend, in-place.
Add a Trend into a TrendList. Merge with the rightmost Trend object, then continue recursively.
- Raises:
TypeError: object being merged not a Trend
- Args:
other: Trend object to stick on the right end
- clear()
Remove all items from list.
- copy()
Return a shallow copy of the list.
- count(value, /)
Return number of occurrences of value.
- extend(iterable, /)
Extend list by appending elements from the iterable.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- insert(index, object, /)
Insert object before index.
- pop(index=- 1, /)
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- remove(value, /)
Remove first occurrence of value.
Raises ValueError if the value is not present.
- reverse()
Reverse IN PLACE.
- rotate() trendlist.trendlist.TrendList
Move the leftmost trend to the right end, then merge.
- Returns:
New trendlist after single, left-to-right rotation and required merge(s).
- single() trendlist.trendlist.Rotations
Rotate until there’s a single trend.
After rotating a list, perhaps more than once, how many rotations did you do, and where, in the original list, was the current head?
- Returns:
Rotations(rotations = # required for single trend, orig_start = where single trend start was in original list)
- sort(*, key=None, reverse=False)
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.