absfuyu.dxt package
Absfuyu: Data Extension
Extension for data type such as list, str, dict, …
Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)
Features:
DictExt
IntExt
ListExt
Text
- class absfuyu.dxt.DictExt[source]
Bases:
ShowAllMethodsMixin,dictdictextension- analyze() DictAnalyzeResult[source]
Analyze all the key values (
int,float) indictthen return highest/lowest index- Returns:
Analyzed data
- Return type:
dict
Example:
>>> test = DictExt({ ... "abc": 9, ... "def": 9, ... "ghi": 8, ... "jkl": 1, ... "mno": 1 ... }) >>> test.analyze() DictAnalyzeResult(max_value=9, min_value=1, max_list=[('abc', 9), ('def', 9)], min_list=[('jkl', 1), ('mno', 1)])
Changed in version 3.3.0: Updated return type
- swap_items() Self[source]
Swap
dict.keys()withdict.values()- Returns:
Swapped dict
- Return type:
Example:
>>> test = DictExt({"abc": 9}) >>> test.swap_items() {9: 'abc'}
- apply(func: Callable, apply_to_value: bool = True) Self[source]
Apply function to
DictExt.keys()orDictExt.values()- Parameters:
func (Callable) – Callable function
apply_to_value (bool) –
True: ApplyfunctoDictExt.values()False: ApplyfunctoDictExt.keys()
- Returns:
DictExt
- Return type:
Example:
>>> test = DictExt({"abc": 9}) >>> test.apply(str) {'abc': '9'}
- aggregate(other_dict: dict, default_value: ~typing.Any = 0, operator_func: ~collections.abc.Callable[[~typing.Any, ~typing.Any], ~typing.Any] = <built-in function add>) Self[source]
Aggregates the values of the current dictionary with another dictionary.
For each unique key, this method applies the specified operator to the values from both dictionaries. If a key exists in only one dictionary, its value is used. If an error occurs during aggregation (e.g., incompatible types), the values from both dictionaries are returned as a list.
- Parameters:
other_dict (dict) – The dictionary to aggregate with.
default_value (Any, optional) – The value to use for missing keys, by default
0
- operator_funcCallable[[Any, Any], Any], optional
A function that takes two arguments and returns a single value, by default
operator.add
- Returns:
A new instance of the aggregated dictionary.
- Return type:
Self
Example:
>>> test = DictExt({"test": 5, "test2": 9}) >>> agg = {"test1": 10, "test2": 1} >>> print(test.aggregate(agg)) {'test1': 10, 'test': 5, 'test2': 10}
>>> test = DictExt({"test": 5, "test2": 9}) >>> agg = {"test1": 10, "test2": "1"} >>> print(test.aggregate(agg)) {'test1': 10, 'test': 5, 'test2': [9, '1']}
Added in version 3.4.0
Changed in version 5.0.0: Updated to handle more types and operator
- class absfuyu.dxt.IntExt[source]
Bases:
ShowAllMethodsMixin,intintextension- to_binary() str[source]
Convert to binary number
- Returns:
Binary number
- Return type:
str
Example:
>>> test = IntNumber(10) >>> test.to_binary() '1010'
- to_celcius_degree() float[source]
Convert into Celcius degree as if
selfis Fahrenheit degree- Returns:
Celcius degree
- Return type:
float
Example:
>>> test = IntNumber(10) >>> test.to_celcius_degree() -12.222222222222221
- to_fahrenheit_degree() float[source]
Convert into Fahrenheit degree as if
selfis Celcius degree- Returns:
Fahrenheit degree
- Return type:
float
Example:
>>> test = IntNumber(10) >>> test.to_fahrenheit_degree() 50.0
- reverse() Self[source]
Reverse a number. Reverse
abs(number)ifnumber < 0- Returns:
Reversed number
- Return type:
IntNumber
Example:
>>> test = IntNumber(102) >>> test.reverse() 201
- is_even() bool[source]
An even number is a number which divisible by 2
- Returns:
Trueif an even numberFalseif not an even number- Return type:
bool
- is_prime() bool[source]
Check if the integer is a prime number or not
A prime number is a natural number greater than
1that is not a product of two smaller natural numbers. A natural number greater than1that is not prime is called a composite number.- Returns:
Trueif a prime numberFalseif not a prime number- Return type:
bool
- is_twisted_prime() bool[source]
A number is said to be twisted prime if it is a prime number and reverse of the number is also a prime number
- Returns:
Trueif a twisted prime numberFalseif not a twisted prime number- Return type:
bool
- is_perfect() bool[source]
Check if integer is perfect number
Perfect number: a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is
6, which is the sum of1,2, and3. Other perfect numbers are28,496, and8,128.- Returns:
Trueif a perfect numberFalseif not a perfect number- Return type:
bool
- is_narcissistic() bool[source]
Check if a narcissistic number
In number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number (after Michael F. Armstrong) or a plus perfect number) in a given number base
bis a number that is the sum of its own digits each raised to the power of the number of digits.- Returns:
Trueif a narcissistic numberFalseif not a narcissistic number- Return type:
bool
- is_palindromic() bool[source]
A palindromic number (also known as a numeral palindrome or a numeric palindrome) is a number (such as
16461) that remains the same when its digits are reversed.- Returns:
Trueif a palindromic numberFalseif not a palindromic number- Return type:
bool
- is_palindromic_prime() bool[source]
A palindormic prime is a number which is both palindromic and prime
- Returns:
Trueif a palindormic prime numberFalseif not a palindormic prime number- Return type:
bool
- lcm(with_number: int) Self[source]
Least common multiple of
selfandwith_number- Parameters:
with_number (int) – The number that want to find LCM with
- Returns:
Least common multiple
- Return type:
IntNumber
Example:
>>> test = IntNumber(102) >>> test.lcm(5) 510
- gcd(with_number: int) Self[source]
Greatest common divisor of
selfandwith_number- Parameters:
with_number (int) – The number that want to find GCD with
- Returns:
Greatest common divisor
- Return type:
IntNumber
Example:
>>> test = IntNumber(1024) >>> test.gcd(8) 8
Changed in version 3.3.0: Updated functionality
- add_to_one_digit(master_number: bool = False) Self[source]
Convert
selfinto 1-digit number by adding all of the digits together- Parameters:
master_number (bool) –
Break when sum =22or11(numerology)(Default:False)- Returns:
IntNumber
- Return type:
IntNumber
Example:
>>> test = IntNumber(119) >>> test.add_to_one_digit() 2
>>> test = IntNumber(119) >>> test.add_to_one_digit(master_number=True) 11
- divisible_list() list[int][source]
A list of divisible number
- Returns:
A list of divisible number
- Return type:
list[int]
Example:
>>> test = IntNumber(1024) >>> test.divisible_list() [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
Changed in version 5.0.0: Removed ``short_form`` parameter
- prime_factor(short_form: bool = True) list[int] | list[Pow][source]
Prime factor
- Parameters:
short_form (bool) –
Show prime list in short formNormal example:[2, 2, 2, 3, 3]Short form example:[2^3, 3^2](Default:True)- Returns:
- List of prime number that when multiplied together ==
selflist[int]: Long formlist[Pow]: Short form - Return type:
list[int] | list[Pow]
Example:
>>> test = IntNumber(1024) >>> test.prime_factor() [2^10]
>>> test = IntNumber(1024) >>> test.prime_factor(short_form=False) [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
- analyze(short_form: bool = True) dict[str, dict[str, Any]][source]
Analyze the number with almost all
IntNumbermethod- Parameters:
short_form (bool) –
Enable short form for some items(Default:True)- Returns:
Detailed analysis
- Return type:
dict[str, dict[str, Any]]
Example:
>>> test = IntNumber(1024) >>> test.analyze() { 'summary': {'number': 1024, 'length': 4, 'even': True, 'prime factor': [2^10], 'divisible': [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]}, 'convert': {'binary': '10000000000', 'octa': '2000', 'hex': '400', 'reverse': 4201, 'add to one': 7}, 'characteristic': {'prime': False, 'twisted prime': False, 'perfect': False, 'narcissistic': False, 'palindromic': False, 'palindromic prime': False} }
- class absfuyu.dxt.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
- class absfuyu.dxt.Text[source]
Bases:
ShowAllMethodsMixin,strstrextension- divide(string_split_size: int = 60) list[str][source]
Divide long string into smaller size
- Parameters:
string_split_size (int) – Divide string every
xcharacter (Default:60)- Returns:
A list in which each item is a smaller string with the size of
string_split_size(need to be concaternate later)- Return type:
list[str]
Example:
>>> test = Text("This is an extremely long line of text!") >>> test.divide(string_split_size=20) ['This is an extremely', ' long line of text!']
- divide_with_variable(split_size: int = 60, split_var_len: int = 12, custom_var_name: str | None = None) list[str][source]
Divide long string into smaller size, then assign a random variable to splited string for later use
- Parameters:
split_size (int) – Divide string every
xcharacter (Default:60)split_var_len (int) – Length of variable name assigned to each item (Default:
12)custom_var_name (str) – Custom variable name when join string
- Returns:
A list in which each item is a smaller string with the size of
split_sizeand a way to concaternate them (when usingprint())- Return type:
list[str]
Example:
>>> test = Text("This is an extremely long line of text!") >>> test.divide_with_variable(split_size=20) [ "qNTCnmkFPTJg='This is an extremely'", "vkmLBUykYYDG=' long line of text!'", 'sBoSwEfoxBIH=qNTCnmkFPTJg+vkmLBUykYYDG', 'sBoSwEfoxBIH' ]
>>> test = Text("This is an extremely long line of text!") >>> test.divide_with_variable(split_size=20, custom_var_name="test") [ "test1='This is an extremely'", "test2=' long line of text!'", 'test=test1+test2', 'test' ]
- analyze(full: bool = False) TextAnalyzeDictFormat[source]
String analyze (count number of type of character)
- Parameters:
full (bool) – Full analyze when
True(Default:False)- Returns:
A dictionary contains number of digit character, uppercase character, lowercase character, and special character
- Return type:
dict | TextAnalyzeDictFormat
Example:
>>> test = Text("Random T3xt!") >>> test.analyze() {'digit': 1, 'uppercase': 2, 'lowercase': 7, 'other': 2}
Changed in version 3.3.0: Updated functionality
- reverse() Self[source]
Reverse the string
- Returns:
Reversed string
- Return type:
Example:
>>> test = Text("Hello, World!") >>> test.reverse() '!dlroW ,olleH'
- is_pangram(custom_alphabet: set[str] | None = None) bool[source]
Check if string is a pangram
A pangram is a unique sentence in which every letter of the alphabet is used at least once
- Parameters:
custom_alphabet (set[str] | None, optional) – Custom alphabet to use (Default:
None)- Returns:
Trueif string is a pangramFalseif string is not a pangram- Return type:
bool
Changed in version 5.0.0: Add ``custom_alphabet`` parameter
- is_palindrome() bool[source]
Check if string is a palindrome
A palindrome is a word, verse, or sentence or a number that reads the same backward or forward
- Returns:
Trueif string is a palindromeFalseif string is not a palindrome- Return type:
bool
- to_hex(raw: bool = False) str[source]
Convert string to hex form
- Parameters:
raw (bool) –
False: hex string in the form of\x(default)True: normal hex string- Returns:
Hexed string
- Return type:
str
Example:
>>> test = Text("Hello, World!") >>> test.to_hex() '\\x48\\x65\\x6c\\x6c\\x6f\\x2c\\x20\\x57\\x6f\\x72\\x6c\\x64\\x21'
- random_capslock(probability: int = 50) Self[source]
Randomly capslock letter in string
- Parameters:
probability (int) – Probability in range [0, 100] (Default:
50)- Returns:
Random capslocked text
- Return type:
Example:
>>> test = Text("This is an extremely long line of text!") >>> test.random_capslock() 'tHis iS An ExtREmELY loNg liNE oF tExT!'
- reverse_capslock() Self[source]
Reverse capslock in string
- Returns:
Reversed capslock
Text- Return type:
Example:
>>> test = Text("Foo") >>> test.reverse_capslock() 'fOO'
Changed in version 5.0.0: Use ``str.swapcase()``
- to_list() list[str][source]
Convert into list
- Returns:
List of string
- Return type:
list[str]
Example:
>>> test = Text("test") >>> test.to_list() ['t', 'e', 's', 't']
- count_pattern(pattern: str, ignore_capslock: bool = False) int[source]
Returns how many times
patternappears in text- Parameters:
pattern (str) – Pattern to count
ignore_capslock (bool) – Ignore the pattern uppercase or lowercase (Default:
False- Exact match)
- Returns:
How many times pattern appeared
- Return type:
int
Example:
>>> Text("test").count_pattern("t") 2
Added in version 3.3.0
- hapax(strict: bool = False) list[str][source]
A hapax legomenon (often abbreviated to hapax) is a word which occurs only once in either the written record of a language, the works of an author, or in a single text.
This function returns a list of hapaxes (if any) (Lettercase is ignored)
- Parameters:
strict (bool) – Remove all special characters before checking for hapax (Default:
False)- Returns:
A list of hapaxes
- Return type:
list[str]
Example:
>>> test = Text("A a. a, b c c= C| d d") >>> test.hapax() ['a', 'a.', 'a,', 'b', 'c', 'c=', 'c|']
>>> test.hapax(strict=True) ['b']
Added in version 3.3.0
- shorten(shorten_size: int = 60) str[source]
Shorten long text
- Parameters:
shorten_size (int, optional) – How many characters per line. Minimum is
1, by default60- Returns:
Shortened text
- Return type:
str
Example:
>>> test = Text("a" * 200) >>> test.shorten() ( 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 'aaaaaaaaaaaaaaaaaaaa' )
Added in version 5.0.0
- class absfuyu.dxt.DictAnalyzeResult(max_value: int | float, min_value: int | float, max_list: list, min_list: list)[source]
Bases:
NamedTupleResult for
DictExt.analyze()- max_value: int | float
Alias for field number 0
- min_value: int | float
Alias for field number 1
- max_list: list
Alias for field number 2
- min_list: list
Alias for field number 3
- class absfuyu.dxt.DictBoolFalse[source]
Bases:
dict[Any,bool]Only show items when
values == Falsein__repr__()
- class absfuyu.dxt.DictBoolTrue[source]
Bases:
dict[Any,bool]Only show items when
values == Truein__repr__()
- class absfuyu.dxt.Pow(number: int | float, power_by: int)[source]
Bases:
objectNumber power by a number
- class absfuyu.dxt.TextAnalyzeDictFormat[source]
Bases:
TypedDictDict format for
Text.analyze()method- Parameters:
digit (int) – Number of digit characters
uppercase (int) – Number of uppercase characters
lowercase (int) – Number of lowercase characters
other (int) – Number of other printable characters
is_pangram (NotRequired[bool]) – Is a pangram (Not required)
is_palindrome (NotRequired[bool]) – Is a palindrome (Not required)
- digit: int
- uppercase: int
- lowercase: int
- other: int
- is_pangram: NotRequired[bool]
- is_palindrome: NotRequired[bool]
Submodules
- absfuyu.dxt.dictext module
- absfuyu.dxt.dxt_support module
- absfuyu.dxt.intext module
- Absfuyu: Data Extension
IntExtIntExt.to_binary()IntExt.to_celcius_degree()IntExt.to_fahrenheit_degree()IntExt.reverse()IntExt.is_even()IntExt.is_prime()IntExt.is_twisted_prime()IntExt.is_perfect()IntExt.is_narcissistic()IntExt.is_palindromic()IntExt.is_palindromic_prime()IntExt.lcm()IntExt.gcd()IntExt.add_to_one_digit()IntExt.divisible_list()IntExt.prime_factor()IntExt.analyze()IntExt.split()
Pow
- absfuyu.dxt.listext module
- Absfuyu: Data Extension
ListExtListExt.stringify()ListExt.head()ListExt.tail()ListExt.sorts()ListExt.freq()ListExt.slice_points()ListExt.pick_one()ListExt.get_random()ListExt.len_items()ListExt.mean_len()ListExt.apply()ListExt.unique()ListExt.group_by_unique()ListExt.group_by_pair_value()ListExt.flatten()ListExt.numbering()ListExt.split_chunk()
- absfuyu.dxt.strext module