istr-python 1.1.36__tar.gz → 1.1.37.post0__tar.gz
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.
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/PKG-INFO +20 -4
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/README.md +19 -3
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr/istr.py +40 -1
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr_python.egg-info/PKG-INFO +20 -4
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/pyproject.toml +1 -1
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/tests/test_istr.py +14 -1
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr/__init__.py +0 -0
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr/istr - Copy.py +0 -0
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.36 → istr_python-1.1.37.post0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.37.post0
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -797,6 +797,16 @@ It is also possible to apply `prod` on an istr:
|
|
|
797
797
|
`istr(1234).prod()` is `istr(24)`
|
|
798
798
|
`istr("123").prod(start=4)` is `istr(24)`
|
|
799
799
|
|
|
800
|
+
#### sum to get sum of an iterable
|
|
801
|
+
|
|
802
|
+
The method `sum` can be used to return the sum of an iterable (including an istr), very much like the builtin sum function.
|
|
803
|
+
Thus, `istr.sum(range(1,5))` is `istr('10')`
|
|
804
|
+
And `istr.sum("123", start=4)` is also `istr('10')`.
|
|
805
|
+
|
|
806
|
+
It is also possible to apply `sum` on an istr:
|
|
807
|
+
`istr(1234).sum()` is `istr('10')`
|
|
808
|
+
`istr("123").prod(start=4)` is `istr('10')`
|
|
809
|
+
|
|
800
810
|
#### sumprod to get the sum of products of iterables
|
|
801
811
|
|
|
802
812
|
The class method `istr.sumprod()`, is equivalent to `math.sumprod()`, but applies istr to both iterables.
|
|
@@ -828,15 +838,15 @@ Note that the result will always be istr-ed, except when the result is None.
|
|
|
828
838
|
|
|
829
839
|
Examples:
|
|
830
840
|
```
|
|
831
|
-
istr(1234).getitem(2) ==>
|
|
841
|
+
istr(1234).getitem(2) ==> 3
|
|
832
842
|
istr(1234).getitem(-2) ==> 3
|
|
833
843
|
istr(1234).getitem(5) ==> istr('')
|
|
834
844
|
istr(1234).getitem(5, '0') ==> istr('0')
|
|
835
845
|
istr(1234).getitem(5, None) ==> None
|
|
836
846
|
```
|
|
837
|
-
This method can also be used with
|
|
847
|
+
This method can also be used with a str. E.g.:
|
|
838
848
|
```
|
|
839
|
-
istr.getitem('1234', 2) ==>
|
|
849
|
+
istr.getitem('1234', 2) ==> 3
|
|
840
850
|
istr.getitem('1234', -2) ==> 3
|
|
841
851
|
istr.getitem('1234', 5) ==> istr('')
|
|
842
852
|
istr.getitem('1234',5, '0') ==> istr('0')
|
|
@@ -844,6 +854,12 @@ istr.getitem('1234',5, None) ==> None
|
|
|
844
854
|
```
|
|
845
855
|
Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
|
|
846
856
|
|
|
857
|
+
#### long square root
|
|
858
|
+
The method `long_sqrt` gives a list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
|
|
859
|
+
E.g. `istr.long_sqrt(123 ** 2)` results in
|
|
860
|
+
|
|
861
|
+
`[istr('123'), istr('015129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
|
|
862
|
+
|
|
847
863
|
#### generate istr with digits
|
|
848
864
|
|
|
849
865
|
The class method `digits` can be used to return an istr of digits according to a given specification.
|
|
@@ -784,6 +784,16 @@ It is also possible to apply `prod` on an istr:
|
|
|
784
784
|
`istr(1234).prod()` is `istr(24)`
|
|
785
785
|
`istr("123").prod(start=4)` is `istr(24)`
|
|
786
786
|
|
|
787
|
+
#### sum to get sum of an iterable
|
|
788
|
+
|
|
789
|
+
The method `sum` can be used to return the sum of an iterable (including an istr), very much like the builtin sum function.
|
|
790
|
+
Thus, `istr.sum(range(1,5))` is `istr('10')`
|
|
791
|
+
And `istr.sum("123", start=4)` is also `istr('10')`.
|
|
792
|
+
|
|
793
|
+
It is also possible to apply `sum` on an istr:
|
|
794
|
+
`istr(1234).sum()` is `istr('10')`
|
|
795
|
+
`istr("123").prod(start=4)` is `istr('10')`
|
|
796
|
+
|
|
787
797
|
#### sumprod to get the sum of products of iterables
|
|
788
798
|
|
|
789
799
|
The class method `istr.sumprod()`, is equivalent to `math.sumprod()`, but applies istr to both iterables.
|
|
@@ -815,15 +825,15 @@ Note that the result will always be istr-ed, except when the result is None.
|
|
|
815
825
|
|
|
816
826
|
Examples:
|
|
817
827
|
```
|
|
818
|
-
istr(1234).getitem(2) ==>
|
|
828
|
+
istr(1234).getitem(2) ==> 3
|
|
819
829
|
istr(1234).getitem(-2) ==> 3
|
|
820
830
|
istr(1234).getitem(5) ==> istr('')
|
|
821
831
|
istr(1234).getitem(5, '0') ==> istr('0')
|
|
822
832
|
istr(1234).getitem(5, None) ==> None
|
|
823
833
|
```
|
|
824
|
-
This method can also be used with
|
|
834
|
+
This method can also be used with a str. E.g.:
|
|
825
835
|
```
|
|
826
|
-
istr.getitem('1234', 2) ==>
|
|
836
|
+
istr.getitem('1234', 2) ==> 3
|
|
827
837
|
istr.getitem('1234', -2) ==> 3
|
|
828
838
|
istr.getitem('1234', 5) ==> istr('')
|
|
829
839
|
istr.getitem('1234',5, '0') ==> istr('0')
|
|
@@ -831,6 +841,12 @@ istr.getitem('1234',5, None) ==> None
|
|
|
831
841
|
```
|
|
832
842
|
Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
|
|
833
843
|
|
|
844
|
+
#### long square root
|
|
845
|
+
The method `long_sqrt` gives a list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
|
|
846
|
+
E.g. `istr.long_sqrt(123 ** 2)` results in
|
|
847
|
+
|
|
848
|
+
`[istr('123'), istr('015129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
|
|
849
|
+
|
|
834
850
|
#### generate istr with digits
|
|
835
851
|
|
|
836
852
|
The class method `digits` can be used to return an istr of digits according to a given specification.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
8
|
+
__version__ = "1.1.37"
|
|
9
9
|
import functools
|
|
10
10
|
import itertools
|
|
11
11
|
import types
|
|
@@ -841,6 +841,9 @@ class istr(str):
|
|
|
841
841
|
|
|
842
842
|
def prod(self, *, start=1):
|
|
843
843
|
return math.prod(self, start=istr(start))
|
|
844
|
+
|
|
845
|
+
def sum(self, / , start=0):
|
|
846
|
+
return sum(istr(self), start=int(start))
|
|
844
847
|
|
|
845
848
|
@classmethod
|
|
846
849
|
def sumprod(cls, p, q, /, strict=True):
|
|
@@ -852,6 +855,42 @@ class istr(str):
|
|
|
852
855
|
def enumerate(cls, iterable, start=0):
|
|
853
856
|
for i, value in enumerate(iterable, int(start)):
|
|
854
857
|
yield cls(i), value
|
|
858
|
+
|
|
859
|
+
def long_sqrt(self):
|
|
860
|
+
"""
|
|
861
|
+
this function does long squre root and returns all the lines to be written.
|
|
862
|
+
(modified from a ChatGPT code suggestion)
|
|
863
|
+
returns root, number (possibly with an extra 0) and the lines below the number, all istr-ed
|
|
864
|
+
"""
|
|
865
|
+
number=istr(istr.interpret_as_str(self))
|
|
866
|
+
lines = []
|
|
867
|
+
|
|
868
|
+
if len(number)%2==1:
|
|
869
|
+
number = "0" | number
|
|
870
|
+
|
|
871
|
+
pairs=list(istr.batched(number,2,join=True))
|
|
872
|
+
root = istr(0)
|
|
873
|
+
remainder = 0
|
|
874
|
+
|
|
875
|
+
for pair in pairs:
|
|
876
|
+
dividend = remainder * 100 + pair
|
|
877
|
+
|
|
878
|
+
x = 0
|
|
879
|
+
for d in range(10):
|
|
880
|
+
if (20 * root + d) * d <= dividend:
|
|
881
|
+
x = d
|
|
882
|
+
else:
|
|
883
|
+
break
|
|
884
|
+
|
|
885
|
+
trial = (20 * root + x) * x
|
|
886
|
+
remainder = dividend - trial
|
|
887
|
+
|
|
888
|
+
root = root * 10 + x
|
|
889
|
+
lines.append(dividend)
|
|
890
|
+
lines.append(trial)
|
|
891
|
+
lines.append(remainder)
|
|
892
|
+
return [root]+[number]+ lines[1:] # ignore the first dividend
|
|
893
|
+
|
|
855
894
|
|
|
856
895
|
def this_base(self):
|
|
857
896
|
return self._this_base
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.37.post0
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -797,6 +797,16 @@ It is also possible to apply `prod` on an istr:
|
|
|
797
797
|
`istr(1234).prod()` is `istr(24)`
|
|
798
798
|
`istr("123").prod(start=4)` is `istr(24)`
|
|
799
799
|
|
|
800
|
+
#### sum to get sum of an iterable
|
|
801
|
+
|
|
802
|
+
The method `sum` can be used to return the sum of an iterable (including an istr), very much like the builtin sum function.
|
|
803
|
+
Thus, `istr.sum(range(1,5))` is `istr('10')`
|
|
804
|
+
And `istr.sum("123", start=4)` is also `istr('10')`.
|
|
805
|
+
|
|
806
|
+
It is also possible to apply `sum` on an istr:
|
|
807
|
+
`istr(1234).sum()` is `istr('10')`
|
|
808
|
+
`istr("123").prod(start=4)` is `istr('10')`
|
|
809
|
+
|
|
800
810
|
#### sumprod to get the sum of products of iterables
|
|
801
811
|
|
|
802
812
|
The class method `istr.sumprod()`, is equivalent to `math.sumprod()`, but applies istr to both iterables.
|
|
@@ -828,15 +838,15 @@ Note that the result will always be istr-ed, except when the result is None.
|
|
|
828
838
|
|
|
829
839
|
Examples:
|
|
830
840
|
```
|
|
831
|
-
istr(1234).getitem(2) ==>
|
|
841
|
+
istr(1234).getitem(2) ==> 3
|
|
832
842
|
istr(1234).getitem(-2) ==> 3
|
|
833
843
|
istr(1234).getitem(5) ==> istr('')
|
|
834
844
|
istr(1234).getitem(5, '0') ==> istr('0')
|
|
835
845
|
istr(1234).getitem(5, None) ==> None
|
|
836
846
|
```
|
|
837
|
-
This method can also be used with
|
|
847
|
+
This method can also be used with a str. E.g.:
|
|
838
848
|
```
|
|
839
|
-
istr.getitem('1234', 2) ==>
|
|
849
|
+
istr.getitem('1234', 2) ==> 3
|
|
840
850
|
istr.getitem('1234', -2) ==> 3
|
|
841
851
|
istr.getitem('1234', 5) ==> istr('')
|
|
842
852
|
istr.getitem('1234',5, '0') ==> istr('0')
|
|
@@ -844,6 +854,12 @@ istr.getitem('1234',5, None) ==> None
|
|
|
844
854
|
```
|
|
845
855
|
Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
|
|
846
856
|
|
|
857
|
+
#### long square root
|
|
858
|
+
The method `long_sqrt` gives a list of the lines of a long square root. Both the result (root) and the original number, possibly with a trailing 0 are returned, along with the calculated values.
|
|
859
|
+
E.g. `istr.long_sqrt(123 ** 2)` results in
|
|
860
|
+
|
|
861
|
+
`[istr('123'), istr('015129'), istr('1'), istr('51'), istr('44'), istr('729'), istr('729'), istr('0')]`
|
|
862
|
+
|
|
847
863
|
#### generate istr with digits
|
|
848
864
|
|
|
849
865
|
The class method `digits` can be used to return an istr of digits according to a given specification.
|
|
@@ -10,7 +10,7 @@ authors = [
|
|
|
10
10
|
{ name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
|
|
11
11
|
]
|
|
12
12
|
description = "istr - strings you can count on"
|
|
13
|
-
version = "1.1.
|
|
13
|
+
version = "1.1.37.post0"
|
|
14
14
|
readme = "README.md"
|
|
15
15
|
requires-python = ">=3.10"
|
|
16
16
|
dependencies = []
|
|
@@ -1066,6 +1066,12 @@ def test_is_triangular():
|
|
|
1066
1066
|
assert istr(424581).is_triangular()
|
|
1067
1067
|
assert not istr(424582).is_triangular()
|
|
1068
1068
|
assert istr.is_triangular(424581)
|
|
1069
|
+
|
|
1070
|
+
def test_sum():
|
|
1071
|
+
assert istr(1234).sum() == istr('10')
|
|
1072
|
+
assert istr.sum('1234') == istr('10')
|
|
1073
|
+
assert istr.sum(1234) == istr('10')
|
|
1074
|
+
assert istr.sum(1234, 5) == istr('15')
|
|
1069
1075
|
|
|
1070
1076
|
|
|
1071
1077
|
def test_prod():
|
|
@@ -1211,7 +1217,14 @@ def test_compose():
|
|
|
1211
1217
|
assert istr(":=") == ":="
|
|
1212
1218
|
assert istr("=") == "="
|
|
1213
1219
|
|
|
1214
|
-
|
|
1220
|
+
def test_long_sqrt():
|
|
1221
|
+
lines=istr.long_sqrt(1234**2)
|
|
1222
|
+
assert lines==[istr('1234'), istr('01522756'), istr('1'), istr('52'), istr('44'), istr('827'), istr('729'), istr('9856'), istr('9856'), istr('0')]
|
|
1223
|
+
lines=istr.long_sqrt(1234**2+1)
|
|
1224
|
+
assert lines==[istr('1234'), istr('01522757'), istr('1'), istr('52'), istr('44'), istr('827'), istr('729'), istr('9857'), istr('9856'), istr('1')]
|
|
1225
|
+
lines=istr(1234**2).long_sqrt()
|
|
1226
|
+
assert lines==[istr('1234'), istr('01522756'), istr('1'), istr('52'), istr('44'), istr('827'), istr('729'), istr('9856'), istr('9856'), istr('0')]
|
|
1227
|
+
|
|
1215
1228
|
if __name__ == "__main__":
|
|
1216
1229
|
pytest.main(["-vv", "-s", "-x", __file__])
|
|
1217
1230
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|