pyiter.list_like
1from typing import Any, Callable, Iterable, List, Union, overload 2from .sequence import Sequence 3from .transform import T, new_transform 4 5 6class ListLike(List[T], Sequence[T]): 7 def __init__(self, iterable: Iterable[T] = []): 8 super().__init__(iterable) 9 self.__transform__ = new_transform(iterable) 10 11 @overload 12 def count(self) -> int: ... 13 @overload 14 def count(self, predicate: Callable[[T], bool]) -> int: ... 15 @overload 16 def count(self, predicate: Callable[[T, int], bool]) -> int: ... 17 @overload 18 def count(self, predicate: Callable[[T, int, Sequence[T]], bool]) -> int: ... 19 def count(self, predicate: Union[Callable[..., bool], Any, None] = None) -> int: 20 """ 21 Returns the number of elements in the Sequence that satisfy the specified [predicate] function. 22 23 Example 1: 24 >>> lst = [1, 2, 3] 25 >>> it(lst).count() 26 3 27 >>> it(lst).count(lambda x: x > 0) 28 3 29 >>> it(lst).count(lambda x: x > 2) 30 1 31 """ 32 if predicate is None: 33 return len(self) 34 predicate = self.__callback_overload_warpper__(predicate) 35 return sum(1 for i in self if predicate(i))
7class ListLike(List[T], Sequence[T]): 8 def __init__(self, iterable: Iterable[T] = []): 9 super().__init__(iterable) 10 self.__transform__ = new_transform(iterable) 11 12 @overload 13 def count(self) -> int: ... 14 @overload 15 def count(self, predicate: Callable[[T], bool]) -> int: ... 16 @overload 17 def count(self, predicate: Callable[[T, int], bool]) -> int: ... 18 @overload 19 def count(self, predicate: Callable[[T, int, Sequence[T]], bool]) -> int: ... 20 def count(self, predicate: Union[Callable[..., bool], Any, None] = None) -> int: 21 """ 22 Returns the number of elements in the Sequence that satisfy the specified [predicate] function. 23 24 Example 1: 25 >>> lst = [1, 2, 3] 26 >>> it(lst).count() 27 3 28 >>> it(lst).count(lambda x: x > 0) 29 3 30 >>> it(lst).count(lambda x: x > 2) 31 1 32 """ 33 if predicate is None: 34 return len(self) 35 predicate = self.__callback_overload_warpper__(predicate) 36 return sum(1 for i in self if predicate(i))
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
Inherited Members
- pyiter.sequence.Sequence
- Sequence
- transforms
- data
- dedup
- dedup_by
- dedup_with_count_by
- dedup_into_group_by
- filter
- filter_is_instance
- filter_not
- filter_not_none
- map
- map_async
- map_not_none
- parallel_map
- find
- find_last
- first
- first_not_none_of
- first_not_none_of_or_none
- first_or_none
- first_or_default
- last
- last_or_none
- index_of_or_none
- index_of
- index_of_or
- index_of_or_else
- last_index_of_or_none
- last_index_of
- last_index_of_or
- last_index_of_or_else
- index_of_first_or_none
- index_of_first
- index_of_first_or
- index_of_first_or_else
- index_of_last_or_none
- index_of_last
- index_of_last_or
- index_of_last_o_else
- single
- single_or_none
- drop
- drop_while
- skip
- skip_while
- take
- take_while
- take_last
- sorted
- sorted_by
- sorted_descending
- sorted_by_descending
- sorted_with
- associate
- associate_by
- associate_by_to
- all
- any
- count
- contains
- element_at
- element_at_or_else
- element_at_or_default
- element_at_or_none
- distinct
- distinct_by
- reduce
- fold
- sum_of
- max_of
- max_by_or_none
- max_by
- min_of
- min_by_or_none
- min_by
- mean_of
- sum
- max
- max_or_default
- max_or_none
- min
- min_or_none
- min_or_default
- mean
- reversed
- flat_map
- flatten
- group_by
- group_by_to
- for_each
- parallel_for_each
- on_each
- parallel_on_each
- zip
- zip_with_next
- unzip
- with_index
- shuffled
- partition
- indexed
- combinations
- nth
- windowed
- chunked
- repeat
- concat
- intersect
- union
- join
- progress
- typing_as
- to_set
- to_dict
- to_list
- to_list_async
- let
- also
- size
- is_empty
- iter
- builtins.list
- clear
- copy
- append
- insert
- extend
- pop
- remove
- index
- reverse
- sort