absfuyu 5.3.0__py3-none-any.whl → 5.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of absfuyu might be problematic. Click here for more details.
- absfuyu/__init__.py +1 -1
- absfuyu/__main__.py +2 -2
- absfuyu/cli/__init__.py +2 -2
- absfuyu/cli/color.py +2 -2
- absfuyu/cli/config_group.py +2 -2
- absfuyu/cli/do_group.py +2 -2
- absfuyu/cli/game_group.py +2 -2
- absfuyu/cli/tool_group.py +2 -2
- absfuyu/config/__init__.py +2 -2
- absfuyu/core/__init__.py +4 -4
- absfuyu/core/baseclass.py +511 -153
- absfuyu/core/baseclass2.py +3 -3
- absfuyu/core/decorator.py +2 -2
- absfuyu/core/docstring.py +2 -2
- absfuyu/core/dummy_cli.py +2 -2
- absfuyu/core/dummy_func.py +2 -2
- absfuyu/dxt/__init__.py +2 -2
- absfuyu/dxt/dictext.py +17 -14
- absfuyu/dxt/dxt_support.py +2 -2
- absfuyu/dxt/intext.py +52 -34
- absfuyu/dxt/listext.py +81 -14
- absfuyu/dxt/strext.py +4 -4
- absfuyu/extra/__init__.py +2 -2
- absfuyu/extra/beautiful.py +2 -2
- absfuyu/extra/da/__init__.py +2 -2
- absfuyu/extra/da/dadf.py +59 -56
- absfuyu/extra/da/dadf_base.py +2 -2
- absfuyu/extra/da/df_func.py +2 -2
- absfuyu/extra/da/mplt.py +2 -2
- absfuyu/extra/data_analysis.py +2 -2
- absfuyu/fun/__init__.py +7 -2
- absfuyu/fun/rubik.py +442 -0
- absfuyu/fun/tarot.py +2 -2
- absfuyu/game/__init__.py +2 -2
- absfuyu/game/game_stat.py +2 -2
- absfuyu/game/sudoku.py +2 -2
- absfuyu/game/tictactoe.py +2 -2
- absfuyu/game/wordle.py +2 -2
- absfuyu/general/__init__.py +2 -2
- absfuyu/general/content.py +4 -4
- absfuyu/general/human.py +2 -2
- absfuyu/general/shape.py +2 -2
- absfuyu/logger.py +2 -2
- absfuyu/pkg_data/__init__.py +2 -2
- absfuyu/pkg_data/deprecated.py +2 -2
- absfuyu/sort.py +2 -2
- absfuyu/tools/__init__.py +2 -2
- absfuyu/tools/checksum.py +2 -2
- absfuyu/tools/converter.py +2 -2
- absfuyu/tools/generator.py +4 -4
- absfuyu/tools/inspector.py +346 -69
- absfuyu/tools/keygen.py +2 -2
- absfuyu/tools/obfuscator.py +4 -4
- absfuyu/tools/passwordlib.py +2 -2
- absfuyu/tools/shutdownizer.py +2 -2
- absfuyu/tools/web.py +2 -2
- absfuyu/typings.py +7 -2
- absfuyu/util/__init__.py +57 -3
- absfuyu/util/api.py +2 -2
- absfuyu/util/json_method.py +2 -2
- absfuyu/util/lunar.py +2 -2
- absfuyu/util/path.py +17 -4
- absfuyu/util/performance.py +2 -2
- absfuyu/util/shorten_number.py +2 -2
- absfuyu/util/text_table.py +33 -14
- absfuyu/util/zipped.py +2 -2
- absfuyu/version.py +3 -3
- {absfuyu-5.3.0.dist-info → absfuyu-5.5.0.dist-info}/METADATA +2 -2
- absfuyu-5.5.0.dist-info/RECORD +77 -0
- absfuyu-5.3.0.dist-info/RECORD +0 -76
- {absfuyu-5.3.0.dist-info → absfuyu-5.5.0.dist-info}/WHEEL +0 -0
- {absfuyu-5.3.0.dist-info → absfuyu-5.5.0.dist-info}/entry_points.txt +0 -0
- {absfuyu-5.3.0.dist-info → absfuyu-5.5.0.dist-info}/licenses/LICENSE +0 -0
absfuyu/core/baseclass2.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Core
|
|
|
3
3
|
-------------
|
|
4
4
|
Bases for other features (with library)
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.5.0
|
|
7
|
+
Date updated: 23/04/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
@@ -71,7 +71,7 @@ class PerformanceTrackingMeta(type):
|
|
|
71
71
|
Usage:
|
|
72
72
|
------
|
|
73
73
|
>>> class Demo(metaclass=PerformanceTrackingMeta):
|
|
74
|
-
... def __init__(self)
|
|
74
|
+
... def __init__(self): ...
|
|
75
75
|
>>> Demo()
|
|
76
76
|
--------------------------------------
|
|
77
77
|
Class: Demo
|
absfuyu/core/decorator.py
CHANGED
absfuyu/core/docstring.py
CHANGED
absfuyu/core/dummy_cli.py
CHANGED
absfuyu/core/dummy_func.py
CHANGED
absfuyu/dxt/__init__.py
CHANGED
absfuyu/dxt/dictext.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Data Extension
|
|
|
3
3
|
-----------------------
|
|
4
4
|
dict extension
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.5.0
|
|
7
|
+
Date updated: 23/04/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
@@ -16,9 +16,18 @@ __all__ = ["DictExt", "DictAnalyzeResult"]
|
|
|
16
16
|
# ---------------------------------------------------------------------------
|
|
17
17
|
import operator
|
|
18
18
|
from collections.abc import Callable
|
|
19
|
-
from typing import Any, NamedTuple, Self
|
|
19
|
+
from typing import Any, NamedTuple, Self, TypeVar
|
|
20
20
|
|
|
21
|
-
from absfuyu.core import
|
|
21
|
+
from absfuyu.core import GetClassMembersMixin, versionadded, versionchanged
|
|
22
|
+
|
|
23
|
+
# from absfuyu.typings import KT as _KT
|
|
24
|
+
# from absfuyu.typings import VT as _VT
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Type
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
|
+
KT = TypeVar("KT")
|
|
30
|
+
VT = TypeVar("VT")
|
|
22
31
|
|
|
23
32
|
|
|
24
33
|
# Class
|
|
@@ -34,7 +43,7 @@ class DictAnalyzeResult(NamedTuple):
|
|
|
34
43
|
min_list: list
|
|
35
44
|
|
|
36
45
|
|
|
37
|
-
class DictExt(
|
|
46
|
+
class DictExt(GetClassMembersMixin, dict[KT, VT]):
|
|
38
47
|
"""
|
|
39
48
|
``dict`` extension
|
|
40
49
|
|
|
@@ -56,13 +65,7 @@ class DictExt(ShowAllMethodsMixin, dict):
|
|
|
56
65
|
|
|
57
66
|
Example:
|
|
58
67
|
--------
|
|
59
|
-
>>> test = DictExt({
|
|
60
|
-
... "abc": 9,
|
|
61
|
-
... "def": 9,
|
|
62
|
-
... "ghi": 8,
|
|
63
|
-
... "jkl": 1,
|
|
64
|
-
... "mno": 1
|
|
65
|
-
... })
|
|
68
|
+
>>> test = DictExt({"abc": 9, "def": 9, "ghi": 8, "jkl": 1, "mno": 1})
|
|
66
69
|
>>> test.analyze()
|
|
67
70
|
DictAnalyzeResult(max_value=9, min_value=1, max_list=[('abc', 9), ('def', 9)], min_list=[('jkl', 1), ('mno', 1)])
|
|
68
71
|
"""
|
|
@@ -106,7 +109,7 @@ class DictExt(ShowAllMethodsMixin, dict):
|
|
|
106
109
|
# return self.__class__(zip(self.values(), self.keys()))
|
|
107
110
|
return self.__class__({v: k for k, v in self.items()})
|
|
108
111
|
|
|
109
|
-
def apply(self, func: Callable, apply_to_value: bool = True) -> Self:
|
|
112
|
+
def apply(self, func: Callable[[Any], Any], apply_to_value: bool = True) -> Self:
|
|
110
113
|
"""
|
|
111
114
|
Apply function to ``DictExt.keys()`` or ``DictExt.values()``
|
|
112
115
|
|
|
@@ -141,7 +144,7 @@ class DictExt(ShowAllMethodsMixin, dict):
|
|
|
141
144
|
@versionadded("3.4.0")
|
|
142
145
|
def aggregate(
|
|
143
146
|
self,
|
|
144
|
-
other_dict: dict,
|
|
147
|
+
other_dict: dict[KT, VT],
|
|
145
148
|
default_value: Any = 0,
|
|
146
149
|
operator_func: Callable[[Any, Any], Any] = operator.add, # operator add
|
|
147
150
|
) -> Self:
|
absfuyu/dxt/dxt_support.py
CHANGED
absfuyu/dxt/intext.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Data Extension
|
|
|
3
3
|
-----------------------
|
|
4
4
|
int extension
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.5.0
|
|
7
|
+
Date updated: 23/04/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
@@ -16,9 +16,10 @@ __all__ = ["IntExt", "Pow"]
|
|
|
16
16
|
# ---------------------------------------------------------------------------
|
|
17
17
|
import math
|
|
18
18
|
from collections import Counter
|
|
19
|
-
from typing import Any, Self
|
|
19
|
+
from typing import Any, Literal, Self, overload
|
|
20
20
|
|
|
21
|
-
from absfuyu.core import
|
|
21
|
+
from absfuyu.core.baseclass import GetClassMembersMixin
|
|
22
|
+
from absfuyu.core.docstring import deprecated, versionadded, versionchanged
|
|
22
23
|
from absfuyu.dxt.dxt_support import DictBoolTrue
|
|
23
24
|
|
|
24
25
|
|
|
@@ -32,20 +33,23 @@ class Pow:
|
|
|
32
33
|
self.power_by = power_by
|
|
33
34
|
|
|
34
35
|
def __str__(self) -> str:
|
|
36
|
+
return self.__repr__()
|
|
37
|
+
|
|
38
|
+
def __repr__(self) -> str:
|
|
35
39
|
if self.power_by == 1:
|
|
36
40
|
return str(self.number)
|
|
37
41
|
else:
|
|
38
42
|
return f"{self.number}^{self.power_by}"
|
|
39
43
|
# return f"{self.__class__.__name__}({self.number}, {self.power_by})"
|
|
40
44
|
|
|
41
|
-
def __repr__(self) -> str:
|
|
42
|
-
return self.__str__()
|
|
43
|
-
|
|
44
45
|
def to_list(self) -> list[int]:
|
|
45
46
|
"""
|
|
46
47
|
Convert into list
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
list[int | float]
|
|
52
|
+
list
|
|
49
53
|
"""
|
|
50
54
|
return [self.number] * self.power_by # type: ignore
|
|
51
55
|
|
|
@@ -53,13 +57,16 @@ class Pow:
|
|
|
53
57
|
"""
|
|
54
58
|
Calculate the ``self.number`` to the power of ``self.power_by``
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
float
|
|
63
|
+
Result
|
|
57
64
|
"""
|
|
58
65
|
# return self.number**self.power_by
|
|
59
66
|
return math.pow(self.number, self.power_by)
|
|
60
67
|
|
|
61
68
|
|
|
62
|
-
class IntExt(
|
|
69
|
+
class IntExt(GetClassMembersMixin, int):
|
|
63
70
|
"""
|
|
64
71
|
``int`` extension
|
|
65
72
|
|
|
@@ -67,7 +74,8 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
67
74
|
>>> IntExt.show_all_methods()
|
|
68
75
|
"""
|
|
69
76
|
|
|
70
|
-
# convert
|
|
77
|
+
# convert
|
|
78
|
+
@deprecated("5.4.0", reason="Use format(...) instead")
|
|
71
79
|
def to_binary(self) -> str:
|
|
72
80
|
"""
|
|
73
81
|
Convert to binary number
|
|
@@ -80,7 +88,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
80
88
|
|
|
81
89
|
Example:
|
|
82
90
|
--------
|
|
83
|
-
>>> test =
|
|
91
|
+
>>> test = IntExt(10)
|
|
84
92
|
>>> test.to_binary()
|
|
85
93
|
'1010'
|
|
86
94
|
"""
|
|
@@ -98,7 +106,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
98
106
|
|
|
99
107
|
Example:
|
|
100
108
|
--------
|
|
101
|
-
>>> test =
|
|
109
|
+
>>> test = IntExt(10)
|
|
102
110
|
>>> test.to_celcius_degree()
|
|
103
111
|
-12.222222222222221
|
|
104
112
|
"""
|
|
@@ -117,7 +125,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
117
125
|
|
|
118
126
|
Example:
|
|
119
127
|
--------
|
|
120
|
-
>>> test =
|
|
128
|
+
>>> test = IntExt(10)
|
|
121
129
|
>>> test.to_fahrenheit_degree()
|
|
122
130
|
50.0
|
|
123
131
|
"""
|
|
@@ -130,13 +138,13 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
130
138
|
|
|
131
139
|
Returns
|
|
132
140
|
-------
|
|
133
|
-
|
|
134
|
-
Reversed number
|
|
141
|
+
Self
|
|
142
|
+
Reversed number.
|
|
135
143
|
|
|
136
144
|
|
|
137
145
|
Example:
|
|
138
146
|
--------
|
|
139
|
-
>>> test =
|
|
147
|
+
>>> test = IntExt(102)
|
|
140
148
|
>>> test.reverse()
|
|
141
149
|
201
|
|
142
150
|
"""
|
|
@@ -384,13 +392,13 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
384
392
|
|
|
385
393
|
Returns
|
|
386
394
|
-------
|
|
387
|
-
|
|
388
|
-
Least common multiple
|
|
395
|
+
Self
|
|
396
|
+
Least common multiple.
|
|
389
397
|
|
|
390
398
|
|
|
391
399
|
Example:
|
|
392
400
|
--------
|
|
393
|
-
>>> test =
|
|
401
|
+
>>> test = IntExt(102)
|
|
394
402
|
>>> test.lcm(5)
|
|
395
403
|
510
|
|
396
404
|
"""
|
|
@@ -408,13 +416,13 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
408
416
|
|
|
409
417
|
Returns
|
|
410
418
|
-------
|
|
411
|
-
|
|
412
|
-
Greatest common divisor
|
|
419
|
+
Self
|
|
420
|
+
Greatest common divisor.
|
|
413
421
|
|
|
414
422
|
|
|
415
423
|
Example:
|
|
416
424
|
--------
|
|
417
|
-
>>> test =
|
|
425
|
+
>>> test = IntExt(1024)
|
|
418
426
|
>>> test.gcd(8)
|
|
419
427
|
8
|
|
420
428
|
"""
|
|
@@ -433,28 +441,31 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
433
441
|
|
|
434
442
|
Returns
|
|
435
443
|
-------
|
|
436
|
-
|
|
437
|
-
|
|
444
|
+
Self
|
|
445
|
+
IntExt
|
|
438
446
|
|
|
439
447
|
|
|
440
448
|
Example:
|
|
441
449
|
--------
|
|
442
|
-
>>> test =
|
|
450
|
+
>>> test = IntExt(119)
|
|
443
451
|
>>> test.add_to_one_digit()
|
|
444
452
|
2
|
|
445
453
|
|
|
446
|
-
>>> test =
|
|
454
|
+
>>> test = IntExt(119)
|
|
447
455
|
>>> test.add_to_one_digit(master_number=True)
|
|
448
456
|
11
|
|
449
457
|
"""
|
|
458
|
+
|
|
450
459
|
number = int(self)
|
|
451
|
-
if number < 0:
|
|
460
|
+
if number < 0: # Convert positive
|
|
452
461
|
number *= -1
|
|
462
|
+
|
|
453
463
|
while len(str(number)) != 1:
|
|
454
464
|
number = sum(map(int, str(number)))
|
|
455
465
|
if master_number:
|
|
456
466
|
if number == 22 or number == 11:
|
|
457
467
|
break # Master number
|
|
468
|
+
|
|
458
469
|
return self.__class__(number)
|
|
459
470
|
|
|
460
471
|
@versionchanged("5.0.0", reason="Removed ``short_form`` parameter")
|
|
@@ -470,7 +481,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
470
481
|
|
|
471
482
|
Example:
|
|
472
483
|
--------
|
|
473
|
-
>>> test =
|
|
484
|
+
>>> test = IntExt(1024)
|
|
474
485
|
>>> test.divisible_list()
|
|
475
486
|
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
|
|
476
487
|
"""
|
|
@@ -481,6 +492,12 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
481
492
|
|
|
482
493
|
return divi_list
|
|
483
494
|
|
|
495
|
+
@overload
|
|
496
|
+
def prime_factor(self) -> list[Pow]: ...
|
|
497
|
+
|
|
498
|
+
@overload
|
|
499
|
+
def prime_factor(self, short_form: Literal[False] = ...) -> list[int]: ...
|
|
500
|
+
|
|
484
501
|
def prime_factor(self, short_form: bool = True) -> list[int] | list[Pow]:
|
|
485
502
|
"""
|
|
486
503
|
Prime factor
|
|
@@ -503,14 +520,15 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
503
520
|
|
|
504
521
|
Example:
|
|
505
522
|
--------
|
|
506
|
-
>>> test =
|
|
523
|
+
>>> test = IntExt(1024)
|
|
507
524
|
>>> test.prime_factor()
|
|
508
525
|
[2^10]
|
|
509
526
|
|
|
510
|
-
>>> test =
|
|
527
|
+
>>> test = IntExt(1024)
|
|
511
528
|
>>> test.prime_factor(short_form=False)
|
|
512
529
|
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
|
|
513
530
|
"""
|
|
531
|
+
|
|
514
532
|
# Generate list
|
|
515
533
|
factors = []
|
|
516
534
|
divisor = 2
|
|
@@ -533,7 +551,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
533
551
|
# analyze
|
|
534
552
|
def analyze(self, short_form: bool = True) -> dict[str, dict[str, Any]]:
|
|
535
553
|
"""
|
|
536
|
-
Analyze the number with almost all ``
|
|
554
|
+
Analyze the number with almost all ``IntExt`` method
|
|
537
555
|
|
|
538
556
|
Parameters
|
|
539
557
|
----------
|
|
@@ -549,7 +567,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
549
567
|
|
|
550
568
|
Example:
|
|
551
569
|
--------
|
|
552
|
-
>>> test =
|
|
570
|
+
>>> test = IntExt(1024)
|
|
553
571
|
>>> test.analyze()
|
|
554
572
|
{
|
|
555
573
|
'summary': {'number': 1024, 'length': 4, 'even': True, 'prime factor': [2^10], 'divisible': [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]},
|
|
@@ -562,7 +580,7 @@ class IntExt(ShowAllMethodsMixin, int):
|
|
|
562
580
|
"number": self,
|
|
563
581
|
"length": len(str(self)),
|
|
564
582
|
"even": self.is_even(),
|
|
565
|
-
"prime factor": self.prime_factor(short_form=short_form),
|
|
583
|
+
"prime factor": self.prime_factor(short_form=short_form), # type: ignore[call-overload]
|
|
566
584
|
"divisible": self.divisible_list(),
|
|
567
585
|
},
|
|
568
586
|
"convert": {
|
absfuyu/dxt/listext.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Data Extension
|
|
|
3
3
|
-----------------------
|
|
4
4
|
list extension
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.5.0
|
|
7
|
+
Date updated: 23/04/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
@@ -18,10 +18,11 @@ import operator
|
|
|
18
18
|
import random
|
|
19
19
|
from collections import Counter
|
|
20
20
|
from collections.abc import Callable, Iterable
|
|
21
|
-
from
|
|
21
|
+
from heapq import heapreplace
|
|
22
|
+
from itertools import accumulate, chain, count, groupby, zip_longest
|
|
22
23
|
from typing import Any, Literal, Self, cast, overload
|
|
23
24
|
|
|
24
|
-
from absfuyu.core.baseclass import
|
|
25
|
+
from absfuyu.core.baseclass import GetClassMembersMixin
|
|
25
26
|
from absfuyu.core.docstring import deprecated, versionadded, versionchanged
|
|
26
27
|
from absfuyu.typings import T as _T
|
|
27
28
|
from absfuyu.util import set_min_max
|
|
@@ -29,7 +30,7 @@ from absfuyu.util import set_min_max
|
|
|
29
30
|
|
|
30
31
|
# Class
|
|
31
32
|
# ---------------------------------------------------------------------------
|
|
32
|
-
class ListExt(
|
|
33
|
+
class ListExt(GetClassMembersMixin, list):
|
|
33
34
|
"""
|
|
34
35
|
``list`` extension
|
|
35
36
|
|
|
@@ -72,6 +73,12 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
72
73
|
-------
|
|
73
74
|
list
|
|
74
75
|
Filtered list
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
Example:
|
|
79
|
+
--------
|
|
80
|
+
>>> ListExt(range(10)).head(2)
|
|
81
|
+
[0, 1]
|
|
75
82
|
"""
|
|
76
83
|
number_of_items = int(
|
|
77
84
|
set_min_max(number_of_items, min_value=0, max_value=len(self))
|
|
@@ -92,6 +99,12 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
92
99
|
-------
|
|
93
100
|
list
|
|
94
101
|
Filtered list
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
Example:
|
|
105
|
+
--------
|
|
106
|
+
>>> ListExt(range(10)).tail(2)
|
|
107
|
+
[8, 9]
|
|
95
108
|
"""
|
|
96
109
|
number_of_items = int(
|
|
97
110
|
set_min_max(number_of_items, min_value=0, max_value=len(self))
|
|
@@ -167,7 +180,6 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
167
180
|
self,
|
|
168
181
|
sort: bool = False,
|
|
169
182
|
num_of_first_char: int | None = None,
|
|
170
|
-
appear_increment: Literal[False] = ...,
|
|
171
183
|
) -> dict: ...
|
|
172
184
|
|
|
173
185
|
@overload
|
|
@@ -330,16 +342,32 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
330
342
|
except TypeError:
|
|
331
343
|
return sep.join(self.apply(str))
|
|
332
344
|
|
|
333
|
-
|
|
345
|
+
@overload
|
|
346
|
+
def numbering(self) -> Self: ...
|
|
347
|
+
|
|
348
|
+
@overload
|
|
349
|
+
def numbering(self, start: int | float = 0) -> Self: ...
|
|
350
|
+
|
|
351
|
+
@overload
|
|
352
|
+
def numbering(self, *, step: int | float = 1) -> Self: ...
|
|
353
|
+
|
|
354
|
+
@overload
|
|
355
|
+
def numbering(self, start: int | float = 0, step: int | float = 1) -> Self: ...
|
|
356
|
+
|
|
357
|
+
@versionchanged("5.5.0", "Use itertools.count to wrap")
|
|
358
|
+
def numbering(self, start: int | float = 0, step: int | float = 1) -> Self:
|
|
334
359
|
"""
|
|
335
360
|
Number the item in list
|
|
336
|
-
(``
|
|
361
|
+
(``itertools.count`` wrapper)
|
|
337
362
|
|
|
338
363
|
Parameters
|
|
339
364
|
----------
|
|
340
|
-
start : int
|
|
365
|
+
start : int | float, optional
|
|
341
366
|
Start from which number, by default ``0``
|
|
342
367
|
|
|
368
|
+
step : int | float, optional
|
|
369
|
+
Step, by default ``1``
|
|
370
|
+
|
|
343
371
|
Returns
|
|
344
372
|
-------
|
|
345
373
|
Self
|
|
@@ -352,8 +380,9 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
352
380
|
>>> test.numbering()
|
|
353
381
|
[(0, 9), (1, 9), (2, 9)]
|
|
354
382
|
"""
|
|
355
|
-
|
|
356
|
-
return self.__class__(enumerate(self, start=start))
|
|
383
|
+
nums = count(start=start, step=step)
|
|
384
|
+
# return self.__class__(enumerate(self, start=start))
|
|
385
|
+
return self.__class__(zip(nums, self))
|
|
357
386
|
|
|
358
387
|
@versionadded("5.3.0") # no test case yet
|
|
359
388
|
def transpose(self, fillvalue: _T | None = None, /) -> Self:
|
|
@@ -608,13 +637,51 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
608
637
|
temp[x].append(item)
|
|
609
638
|
|
|
610
639
|
# Flatten dict.values
|
|
611
|
-
for k, v in temp.items()
|
|
612
|
-
temp[k] = list(set(chain(*v)))
|
|
640
|
+
temp = {k: list(set(chain(*v))) for k, v in temp.items()}
|
|
613
641
|
|
|
614
642
|
iter = list(temp.values())
|
|
615
643
|
|
|
616
644
|
return list(x for x, _ in groupby(iter))
|
|
617
645
|
|
|
646
|
+
@versionadded("5.5.0")
|
|
647
|
+
def split_equal(self, n: int, sort: bool = True) -> Self:
|
|
648
|
+
"""
|
|
649
|
+
Try to equally split a list of number into ``n`` equal sum parts.
|
|
650
|
+
|
|
651
|
+
**Note:** Element in list must be a number.
|
|
652
|
+
|
|
653
|
+
Parameters
|
|
654
|
+
----------
|
|
655
|
+
n : int
|
|
656
|
+
Split into how many parts. Must be >= 1.
|
|
657
|
+
|
|
658
|
+
sort : bool, optional
|
|
659
|
+
Sort the instance before split, by default ``True``
|
|
660
|
+
|
|
661
|
+
Returns
|
|
662
|
+
-------
|
|
663
|
+
Self
|
|
664
|
+
Splitted (list[list])
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
Example:
|
|
668
|
+
--------
|
|
669
|
+
>>> ListExt(range(1, 11)).split_equal(2)
|
|
670
|
+
[[10, 7, 5, 4, 1], [9, 8, 6, 3, 2]]
|
|
671
|
+
"""
|
|
672
|
+
|
|
673
|
+
# https://stackoverflow.com/a/61649667
|
|
674
|
+
bins: list[list[int]] = [[0] for _ in range(max(n, 1))]
|
|
675
|
+
if sort:
|
|
676
|
+
# self = self.sorts(reverse=True)
|
|
677
|
+
self = self.__class__(sorted(self, reverse=True))
|
|
678
|
+
for x in self:
|
|
679
|
+
least = bins[0]
|
|
680
|
+
least[0] += x
|
|
681
|
+
least.append(x)
|
|
682
|
+
heapreplace(bins, least)
|
|
683
|
+
return self.__class__(x[1:] for x in bins)
|
|
684
|
+
|
|
618
685
|
# Slicing
|
|
619
686
|
def slice_points(self, points: list[int]) -> Self:
|
|
620
687
|
"""
|
|
@@ -700,7 +767,7 @@ class ListExt(ShowAllMethodsMixin, list):
|
|
|
700
767
|
|
|
701
768
|
Example:
|
|
702
769
|
--------
|
|
703
|
-
>>> ins = ListExt(range(1,20))
|
|
770
|
+
>>> ins = ListExt(range(1, 20))
|
|
704
771
|
|
|
705
772
|
>>> # Normal split chunk
|
|
706
773
|
>>> ins.split_chunk(10)
|
absfuyu/dxt/strext.py
CHANGED
|
@@ -3,8 +3,8 @@ Absfuyu: Data Extension
|
|
|
3
3
|
-----------------------
|
|
4
4
|
str extension
|
|
5
5
|
|
|
6
|
-
Version: 5.
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.5.0
|
|
7
|
+
Date updated: 23/04/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module Package
|
|
@@ -18,7 +18,7 @@ import random
|
|
|
18
18
|
from string import ascii_letters as _ascii_letters
|
|
19
19
|
from typing import NotRequired, Self, TypedDict
|
|
20
20
|
|
|
21
|
-
from absfuyu.core import
|
|
21
|
+
from absfuyu.core import GetClassMembersMixin, deprecated, versionadded, versionchanged
|
|
22
22
|
from absfuyu.util import set_min_max
|
|
23
23
|
|
|
24
24
|
|
|
@@ -116,7 +116,7 @@ class TextAnalyzeDictFormat(TypedDict):
|
|
|
116
116
|
is_palindrome: NotRequired[bool]
|
|
117
117
|
|
|
118
118
|
|
|
119
|
-
class Text(
|
|
119
|
+
class Text(GetClassMembersMixin, str):
|
|
120
120
|
"""
|
|
121
121
|
``str`` extension
|
|
122
122
|
|
absfuyu/extra/__init__.py
CHANGED
absfuyu/extra/beautiful.py
CHANGED