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, dict

dict extension

analyze() DictAnalyzeResult[source]

Analyze all the key values (int, float) in dict then 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() with dict.values()

Returns:

Swapped dict

Return type:

DictExt

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() or DictExt.values()

Parameters:
  • func (Callable) – Callable function

  • apply_to_value (bool) –

    True: Apply func to DictExt.values()
    False: Apply func to DictExt.keys()

Returns:

DictExt

Return type:

DictExt

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, int

int extension

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 self is 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 self is 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) if number < 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:

True if an even number
False if 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 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number.

Returns:

True if a prime number
False if 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:

True if a twisted prime number
False if 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 of 1, 2, and 3. Other perfect numbers are 28, 496, and 8,128.

Returns:

True if a perfect number
False if 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 b is a number that is the sum of its own digits each raised to the power of the number of digits.

Returns:

True if a narcissistic number
False if 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:

True if a palindromic number
False if 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:

True if a palindormic prime number
False if not a palindormic prime number

Return type:

bool

lcm(with_number: int) Self[source]

Least common multiple of self and with_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 self and with_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 self into 1-digit number by adding all of the digits together

Parameters:

master_number (bool) –

Break when sum = 22 or 11 (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 form
Normal example: [2, 2, 2, 3, 3]
Short form example: [2^3, 3^2]
(Default: True)

Returns:

List of prime number that when multiplied together == self
list[int]: Long form
list[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 IntNumber method

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}
}
split(parts: int) list[int][source]

Evenly split the number into parts parts

Parameters:

parts (int) – Split by how many parts

Returns:

List of evenly splitted numbers

Return type:

list[int]

Example:

>>> IntExt(10).split(4)
[2, 2, 3, 3]

Added in version 5.1.0

class absfuyu.dxt.ListExt(iterable=(), /)[source]

Bases: ShowAllMethodsMixin, list

list extension

stringify() Self[source]

Convert all item in list into string

Returns:

A list with all items with type <str`>

Return type:

ListExt

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_items items in ListExt

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_items items in ListExt

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) –

if True then sort in descending order
if False then sort in ascending order
(Default: False)

Returns:

A sorted list

Return type:

ListExt

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) –

    if True: Sorts the output in ascending order
    if False: No sort

  • num_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 points argument 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_items random items in ListExt

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 in list[str]

Returns:

List of len()’ed value

Return type:

ListExt

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:

ListExt

Example:

>>> test = ListExt([1, 2, 3])
>>> test.apply(str)
['1', '2', '3']
unique() Self[source]

Remove duplicates

Returns:

Duplicates removed list

Return type:

ListExt

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:

ListExt

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 list in list is a pair value, returns a list contain 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:

ListExt

Example:

>>> test = ListExt([["test"], ["test", "test"], ["test"]])
>>> test.flatten()
['test', 'test', 'test', 'test']
numbering(start: int = 0) Self[source]

Number the item in list (enumerate wrapper)

Parameters:

start (int) – Start from which number (Default: 0)

Returns:

Counted list

Return type:

ListExt

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, str

str extension

divide(string_split_size: int = 60) list[str][source]

Divide long string into smaller size

Parameters:

string_split_size (int) – Divide string every x character (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 x character (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_size and a way to concaternate them (when using print())

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:

Text

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:

True if string is a pangram
False if 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:

True if string is a palindrome
False if 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:

Text

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:

Text

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']
to_listext() None[source]

Deprecated, will be removed soon

Deprecated in version 5.0.0: Unused

count_pattern(pattern: str, ignore_capslock: bool = False) int[source]

Returns how many times pattern appears 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 default 60

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: NamedTuple

Result 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 == False in __repr__()

class absfuyu.dxt.DictBoolTrue[source]

Bases: dict[Any, bool]

Only show items when values == True in __repr__()

class absfuyu.dxt.ListNoDunder(iterable=(), /)[source]

Bases: list[str]

Use with object.__dir__()

class absfuyu.dxt.ListREPR(iterable=(), /)[source]

Bases: list

Show list in shorter form

class absfuyu.dxt.Pow(number: int | float, power_by: int)[source]

Bases: object

Number power by a number

to_list() list[int][source]

Convert into list

Return type:

list[int | float]

calculate() float[source]

Calculate the self.number to the power of self.power_by

Return type:

float

class absfuyu.dxt.TextAnalyzeDictFormat[source]

Bases: TypedDict

Dict 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