absfuyu.dxt.listext module
Absfuyu: Data Extension
list extension
Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)
- class absfuyu.dxt.listext.ListExt(iterable=(), /)[source]
Bases:
ShowAllMethodsMixin,listlistextension- stringify() Self[source]
Convert all item in
listinto string- Returns:
A list with all items with type <str`>
- Return type:
Example:
>>> test = ListExt([1, 1, 1, 2, 2, 3]) >>> test.stringify() ['1', '1', '1', '2', '2', '3']
- head(number_of_items: int = 5) list[source]
Show first
number_of_itemsitems inListExt- Parameters:
number_of_items (int) –
Number of items to shows at once(Default:5)- Returns:
Filtered list
- Return type:
list
- tail(number_of_items: int = 5) list[source]
Show last
number_of_itemsitems inListExt- Parameters:
number_of_items (int) –
Number of items to shows at once(Default:5)- Returns:
Filtered list
- Return type:
list
- sorts(reverse: bool = False) Self[source]
Sort all items (with different type) in
list- Parameters:
reverse (bool) –
ifTruethen sort in descending orderifFalsethen sort in ascending order(Default:False)- Returns:
A sorted list
- Return type:
Example:
>>> test = ListExt([9, "abc", 3.5, "aaa", 1, 1.4]) >>> test.sorts() [1, 9, 'aaa', 'abc', 1.4, 3.5]
- freq(sort: bool = False, num_of_first_char: int | None = None, appear_increment: bool = False) dict | list[int][source]
Find frequency of each item in list
- Parameters:
sort (bool) –
ifTrue: Sorts the output in ascending orderifFalse: No sortnum_of_first_char (int | None) –
Number of first character taken into account to sort(Default:None)(num_of_first_char =1: first character in each item)appear_increment (bool) –
return incremental index list of each item when sort(Default:False)
- Returns:
dict – A dict that show frequency
list[int] – Incremental index list
Example:
>>> test = ListExt([1, 1, 2, 3, 5, 5]) >>> test.freq() {1: 2, 2: 1, 3: 1, 5: 2}
>>> test = ListExt([1, 1, 2, 3, 3, 4, 5, 6]) >>> test.freq(appear_increment=True) [2, 3, 5, 6, 7, 8]
- slice_points(points: list[int]) list[list][source]
Splits a list into sublists based on specified split points (indices).
This method divides the original list into multiple sublists. The
pointsargument provides the indices at which the list should be split. The resulting list of lists contains the sublists created by these splits. The original list is not modified.- Parameters:
points (list) – A list of integer indices representing the points at which to split the list. These indices are exclusive of the starting sublist but inclusive of the ending sublist.
- Returns:
A list of lists, where each inner list is a slice of the original list defined by the provided split points.
- Return type:
list[list]
Example:
>>> test = ListExt([1, 1, 2, 3, 3, 4, 5, 6]) >>> test.slice_points([2, 5]) [[1, 1], [2, 3, 3], [4, 5, 6]] >>> test.slice_points([0, 1, 2, 3, 4, 5, 6, 7, 8]) [[], [1], [1], [2], [3], [3], [4], [5], [6]] >>> test.slice_points([]) [[1, 1, 2, 3, 3, 4, 5, 6]]
- pick_one() Any[source]
Pick one random items from
list- Returns:
Random value
- Return type:
Any
Example:
>>> test = ListExt(["foo", "bar"]) >>> test.pick_one() 'bar'
- get_random(number_of_items: int = 5) list[source]
Get
number_of_itemsrandom items inListExt- Parameters:
number_of_items (int) –
Number random of items(Default:5)- Returns:
Filtered list
- Return type:
list
- len_items() Self[source]
len()for every item inlist[str]- Returns:
List of
len()’ed value- Return type:
Example:
>>> test = ListExt(["foo", "bar", "pizza"]) >>> test.len_items() [3, 3, 5]
- mean_len() float[source]
Average length of every item
- Returns:
Average length
- Return type:
float
Example:
>>> test = ListExt(["foo", "bar", "pizza"]) >>> test.mean_len() 3.6666666666666665
- apply(func: Callable[[Any], Any]) Self[source]
Apply function to each entry
- Parameters:
func (Callable) – Callable function
- Returns:
ListExt
- Return type:
Example:
>>> test = ListExt([1, 2, 3]) >>> test.apply(str) ['1', '2', '3']
- unique() Self[source]
Remove duplicates
- Returns:
Duplicates removed list
- Return type:
Example:
>>> test = ListExt([1, 1, 1, 2, 2, 3]) >>> test.unique() [1, 2, 3]
- group_by_unique() Self[source]
Group duplicated elements into list
- Returns:
Grouped value
- Return type:
Example:
>>> test = ListExt([1, 2, 3, 1, 3, 3, 2]) >>> test.group_by_unique() [[1, 1], [2, 2], [3, 3, 3]]
- group_by_pair_value(max_loop: int = 3) list[list][source]
Assume each
listinlistis a pair value, returns alistcontain all paired value- Parameters:
max_loop (int) – Times to run functions (minimum:
3)- Returns:
Grouped value
- Return type:
list[list]
Example:
>>> test = ListExt([[1, 2], [2, 3], [4, 3], [5, 6]]) >>> test.group_by_pair_value() [[1, 2, 3, 4], [5, 6]]
>>> test = ListExt([[8, 3], [4, 6], [6, 3], [5, 2], [7, 2]]) >>> test.group_by_pair_value() [[8, 3, 4, 6], [2, 5, 7]]
>>> test = ListExt([["a", 4], ["b", 4], [5, "c"]]) >>> test.group_by_pair_value() [['a', 4, 'b'], ['c', 5]]
- flatten() Self[source]
Flatten the list
- Returns:
Flattened list
- Return type:
Example:
>>> test = ListExt([["test"], ["test", "test"], ["test"]]) >>> test.flatten() ['test', 'test', 'test', 'test']
- numbering(start: int = 0) Self[source]
Number the item in list (
enumeratewrapper)- Parameters:
start (int) – Start from which number (Default:
0)- Returns:
Counted list
- Return type:
Example:
>>> test = ListExt([9, 9, 9]) >>> test.numbering() [(0, 9), (1, 9), (2, 9)]
- split_chunk(chunk_size: int) list[list][source]
Split list into smaller chunks
- Parameters:
chunk_size (int) – Chunk size, minimum:
1- Returns:
List of chunk
- Return type:
list[list]
Example:
>>> ListExt([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]).split_chunk(5) [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1]]
Added in version 5.1.0