istr-python 1.1.35.post0__tar.gz → 1.1.37__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.35.post0
3
+ Version: 1.1.37
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
@@ -379,7 +379,7 @@ In contrast to the builtin `range`, `istr.range` supports a non keyword paramete
379
379
  `list(istr.range(length=3))` is equivalent to `istr.range(100, 1000)`
380
380
 
381
381
  #### square root, cubic root and nth root
382
- These methods provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default istr('0') will be returned.
382
+ The methods `sqrt`, `cbrt`, `nth_root`provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default `istr('0')` will be returned.
383
383
  ```
384
384
  istr(64).sqrt() ==> istr('8')
385
385
  istr(65).sqrt() ==> istr('0')
@@ -391,7 +391,7 @@ istr(1234**5+1).nth_root(5, 1) ==> istr('1')
391
391
  istr(1234**5+1).nth_root(5, None) ==> None
392
392
 
393
393
  istr.sqrt(64) ==> istr('8')
394
- ```
394
+ ```
395
395
 
396
396
  #### integer division
397
397
  The method `divided_by` not only tests divisibility, but also returns the result of the division. If not possible, `istr('0')` will be returned, unless the *fallback* (last argument) is given, in which case *fallback* will be returned.
@@ -407,6 +407,7 @@ istr(19).divided_by(istr(3)) ==> istr('0')
407
407
  istr.divided_by(18, 3) ==> 6
408
408
  istr.divided_by(19, 3) ==> istr('0')
409
409
  istr.divided_by(19, 3, 1) ==> istr('1')
410
+ ```
410
411
 
411
412
  #### test for even/odd
412
413
 
@@ -440,16 +441,16 @@ istr.is_palindrome(min) ==> False
440
441
  #### test for increasing, decreasing, non-decreasing and non-increasing
441
442
 
442
443
  It is possible to test whether the characters of an istr are increasing, decreasing, non-decreasing or non-increasing, like
443
- ```
444
+ ```
444
445
  istr(1223).is_increasing() ==> False
445
446
  istr(1223).is_non_decreasing() ==> True
446
447
  istr(3221).is_decreasing() ==> False
447
448
  istr(3221).is_non_increasing ==> True
448
- ```
449
- It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
450
449
  ```
450
+ It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
451
+ ```
451
452
  istr.is_increasing(123) ==> True
452
- ```
453
+ ```
453
454
 
454
455
  #### test for divisibility
455
456
 
@@ -466,7 +467,6 @@ It is also possible to test for divisibility of an ordinary int:
466
467
  istr.is_divisible(18, 3) ==> True
467
468
  istr.is_divisible(19, 3) ==> False
468
469
  ```
469
- ```
470
470
  #### test for square
471
471
 
472
472
  It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
@@ -763,11 +763,11 @@ istr.count(10,3) ==> istr('10'), istr('13'), istr('16'), ...
763
763
  #### istr.zip
764
764
 
765
765
  The class method `istr.zip` is the equivalent of the zip builtin, but applies istr to each element. `istr.zip` also supports the join parameter:
766
- ```
766
+ ```
767
767
  print(list(istr.zip('12', '345')))
768
768
  print(list(istr.zip('12', '345', join=True)))
769
769
  print(list(istr.zip('12', '345', strict=True)))
770
- ```
770
+ ```
771
771
  results in
772
772
  ```
773
773
  [(istr('1'), istr('3')), (istr('2'), istr('4'))]
@@ -781,11 +781,11 @@ to `istr` and then concatenate these.
781
781
 
782
782
  `
783
783
 
784
- ```
784
+ ```
785
785
  list(istr.concat(((1,2),(3,4))) ==> istr([12,34])
786
786
  list(istr.concat(istr.permutations(range(3),2))) ==>
787
787
  [istr('01'), istr('02'), istr('10'), istr('12'), istr('20'), istr('21')]
788
- ```
788
+ ```
789
789
 
790
790
  #### prod to get product of an iterable
791
791
 
@@ -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) ==> 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 an str. E.g.:
847
+ This method can also be used with a str. E.g.:
838
848
  ```
839
- istr.getitem('1234', 2) ==> 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')
@@ -1115,29 +1125,29 @@ operator/function int str Example
1115
1125
  + x istr(20) + 3 ==> istr('23')
1116
1126
  _ x istr(20) - 3 ==> istr('17')
1117
1127
  * x istr(20) * 3 ==> istr('60')
1118
- / x istr(20) / 3 ==> istr('6')
1119
- // x istr(20) // 3 ==> istr('6')
1120
- % x istr(20) % 3 ==> istr('2')
1121
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1122
- ** x istr(2) ** 3 ==> istr('8')
1123
- <=, <, >, >= x istr('100') > istr('2') ==> True
1124
- abs x abs(istr(-20)) ==> istr('20')
1125
- int x int(istr("20")) ==> 20
1126
- float x float(istr("20")) ==> 20.0
1127
- complex x complex(istr("20")) ==> (20+0j)
1128
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1129
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1130
- @ x istr(20) @ 3 ==> istr('202020')
1131
- | x istr(20) | '5' ==> istr('205')
1132
- slicing x istr(12345)[1:3] ==> istr('23')
1133
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1134
- len x len(istr(' 20 ')) ==> 4
1135
- count x istr(100).count(0) ==> 2
1128
+ / x istr(20) / 3 ==> istr('6')
1129
+ // x istr(20) // 3 ==> istr('6')
1130
+ % x istr(20) % 3 ==> istr('2')
1131
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1132
+ ** x istr(2) ** 3 ==> istr('8')
1133
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1134
+ abs x abs(istr(-20)) ==> istr('20')
1135
+ int x int(istr("20")) ==> 20
1136
+ float x float(istr("20")) ==> 20.0
1137
+ complex x complex(istr("20")) ==> (20+0j)
1138
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1139
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1140
+ @ x istr(20) @ 3 ==> istr('202020')
1141
+ | x istr(20) | '5' ==> istr('205')
1142
+ slicing x istr(12345)[1:3] ==> istr('23')
1143
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1144
+ len x len(istr(' 20 ')) ==> 4
1145
+ count x istr(100).count(0) ==> 2
1136
1146
  istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1137
- index x istr(' 100 ').index('0') ==> 2
1138
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1139
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1140
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1147
+ index x istr(' 100 ').index('0') ==> 2
1148
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1149
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1150
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1141
1151
  istr('aAbBcC').islower() ==> False
1142
1152
  istr(' abc ').strip() ==> istr('abc')
1143
1153
  ...
@@ -366,7 +366,7 @@ In contrast to the builtin `range`, `istr.range` supports a non keyword paramete
366
366
  `list(istr.range(length=3))` is equivalent to `istr.range(100, 1000)`
367
367
 
368
368
  #### square root, cubic root and nth root
369
- These methods provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default istr('0') will be returned.
369
+ The methods `sqrt`, `cbrt`, `nth_root`provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default `istr('0')` will be returned.
370
370
  ```
371
371
  istr(64).sqrt() ==> istr('8')
372
372
  istr(65).sqrt() ==> istr('0')
@@ -378,7 +378,7 @@ istr(1234**5+1).nth_root(5, 1) ==> istr('1')
378
378
  istr(1234**5+1).nth_root(5, None) ==> None
379
379
 
380
380
  istr.sqrt(64) ==> istr('8')
381
- ```
381
+ ```
382
382
 
383
383
  #### integer division
384
384
  The method `divided_by` not only tests divisibility, but also returns the result of the division. If not possible, `istr('0')` will be returned, unless the *fallback* (last argument) is given, in which case *fallback* will be returned.
@@ -394,6 +394,7 @@ istr(19).divided_by(istr(3)) ==> istr('0')
394
394
  istr.divided_by(18, 3) ==> 6
395
395
  istr.divided_by(19, 3) ==> istr('0')
396
396
  istr.divided_by(19, 3, 1) ==> istr('1')
397
+ ```
397
398
 
398
399
  #### test for even/odd
399
400
 
@@ -427,16 +428,16 @@ istr.is_palindrome(min) ==> False
427
428
  #### test for increasing, decreasing, non-decreasing and non-increasing
428
429
 
429
430
  It is possible to test whether the characters of an istr are increasing, decreasing, non-decreasing or non-increasing, like
430
- ```
431
+ ```
431
432
  istr(1223).is_increasing() ==> False
432
433
  istr(1223).is_non_decreasing() ==> True
433
434
  istr(3221).is_decreasing() ==> False
434
435
  istr(3221).is_non_increasing ==> True
435
- ```
436
- It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
437
436
  ```
437
+ It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
438
+ ```
438
439
  istr.is_increasing(123) ==> True
439
- ```
440
+ ```
440
441
 
441
442
  #### test for divisibility
442
443
 
@@ -453,7 +454,6 @@ It is also possible to test for divisibility of an ordinary int:
453
454
  istr.is_divisible(18, 3) ==> True
454
455
  istr.is_divisible(19, 3) ==> False
455
456
  ```
456
- ```
457
457
  #### test for square
458
458
 
459
459
  It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
@@ -750,11 +750,11 @@ istr.count(10,3) ==> istr('10'), istr('13'), istr('16'), ...
750
750
  #### istr.zip
751
751
 
752
752
  The class method `istr.zip` is the equivalent of the zip builtin, but applies istr to each element. `istr.zip` also supports the join parameter:
753
- ```
753
+ ```
754
754
  print(list(istr.zip('12', '345')))
755
755
  print(list(istr.zip('12', '345', join=True)))
756
756
  print(list(istr.zip('12', '345', strict=True)))
757
- ```
757
+ ```
758
758
  results in
759
759
  ```
760
760
  [(istr('1'), istr('3')), (istr('2'), istr('4'))]
@@ -768,11 +768,11 @@ to `istr` and then concatenate these.
768
768
 
769
769
  `
770
770
 
771
- ```
771
+ ```
772
772
  list(istr.concat(((1,2),(3,4))) ==> istr([12,34])
773
773
  list(istr.concat(istr.permutations(range(3),2))) ==>
774
774
  [istr('01'), istr('02'), istr('10'), istr('12'), istr('20'), istr('21')]
775
- ```
775
+ ```
776
776
 
777
777
  #### prod to get product of an iterable
778
778
 
@@ -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) ==> 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 an str. E.g.:
834
+ This method can also be used with a str. E.g.:
825
835
  ```
826
- istr.getitem('1234', 2) ==> 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')
@@ -1102,29 +1112,29 @@ operator/function int str Example
1102
1112
  + x istr(20) + 3 ==> istr('23')
1103
1113
  _ x istr(20) - 3 ==> istr('17')
1104
1114
  * x istr(20) * 3 ==> istr('60')
1105
- / x istr(20) / 3 ==> istr('6')
1106
- // x istr(20) // 3 ==> istr('6')
1107
- % x istr(20) % 3 ==> istr('2')
1108
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1109
- ** x istr(2) ** 3 ==> istr('8')
1110
- <=, <, >, >= x istr('100') > istr('2') ==> True
1111
- abs x abs(istr(-20)) ==> istr('20')
1112
- int x int(istr("20")) ==> 20
1113
- float x float(istr("20")) ==> 20.0
1114
- complex x complex(istr("20")) ==> (20+0j)
1115
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1116
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1117
- @ x istr(20) @ 3 ==> istr('202020')
1118
- | x istr(20) | '5' ==> istr('205')
1119
- slicing x istr(12345)[1:3] ==> istr('23')
1120
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1121
- len x len(istr(' 20 ')) ==> 4
1122
- count x istr(100).count(0) ==> 2
1115
+ / x istr(20) / 3 ==> istr('6')
1116
+ // x istr(20) // 3 ==> istr('6')
1117
+ % x istr(20) % 3 ==> istr('2')
1118
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1119
+ ** x istr(2) ** 3 ==> istr('8')
1120
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1121
+ abs x abs(istr(-20)) ==> istr('20')
1122
+ int x int(istr("20")) ==> 20
1123
+ float x float(istr("20")) ==> 20.0
1124
+ complex x complex(istr("20")) ==> (20+0j)
1125
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1126
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1127
+ @ x istr(20) @ 3 ==> istr('202020')
1128
+ | x istr(20) | '5' ==> istr('205')
1129
+ slicing x istr(12345)[1:3] ==> istr('23')
1130
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1131
+ len x len(istr(' 20 ')) ==> 4
1132
+ count x istr(100).count(0) ==> 2
1123
1133
  istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1124
- index x istr(' 100 ').index('0') ==> 2
1125
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1126
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1127
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1134
+ index x istr(' 100 ').index('0') ==> 2
1135
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1136
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1137
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1128
1138
  istr('aAbBcC').islower() ==> False
1129
1139
  istr(' abc ').strip() ==> istr('abc')
1130
1140
  ...
@@ -5,7 +5,7 @@
5
5
  # |_||___/ \__||_|
6
6
  # strings you can count on
7
7
 
8
- __version__ = "1.1.35"
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.35.post0
3
+ Version: 1.1.37
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
@@ -379,7 +379,7 @@ In contrast to the builtin `range`, `istr.range` supports a non keyword paramete
379
379
  `list(istr.range(length=3))` is equivalent to `istr.range(100, 1000)`
380
380
 
381
381
  #### square root, cubic root and nth root
382
- These methods provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default istr('0') will be returned.
382
+ The methods `sqrt`, `cbrt`, `nth_root`provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default `istr('0')` will be returned.
383
383
  ```
384
384
  istr(64).sqrt() ==> istr('8')
385
385
  istr(65).sqrt() ==> istr('0')
@@ -391,7 +391,7 @@ istr(1234**5+1).nth_root(5, 1) ==> istr('1')
391
391
  istr(1234**5+1).nth_root(5, None) ==> None
392
392
 
393
393
  istr.sqrt(64) ==> istr('8')
394
- ```
394
+ ```
395
395
 
396
396
  #### integer division
397
397
  The method `divided_by` not only tests divisibility, but also returns the result of the division. If not possible, `istr('0')` will be returned, unless the *fallback* (last argument) is given, in which case *fallback* will be returned.
@@ -407,6 +407,7 @@ istr(19).divided_by(istr(3)) ==> istr('0')
407
407
  istr.divided_by(18, 3) ==> 6
408
408
  istr.divided_by(19, 3) ==> istr('0')
409
409
  istr.divided_by(19, 3, 1) ==> istr('1')
410
+ ```
410
411
 
411
412
  #### test for even/odd
412
413
 
@@ -440,16 +441,16 @@ istr.is_palindrome(min) ==> False
440
441
  #### test for increasing, decreasing, non-decreasing and non-increasing
441
442
 
442
443
  It is possible to test whether the characters of an istr are increasing, decreasing, non-decreasing or non-increasing, like
443
- ```
444
+ ```
444
445
  istr(1223).is_increasing() ==> False
445
446
  istr(1223).is_non_decreasing() ==> True
446
447
  istr(3221).is_decreasing() ==> False
447
448
  istr(3221).is_non_increasing ==> True
448
- ```
449
- It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
450
449
  ```
450
+ It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
451
+ ```
451
452
  istr.is_increasing(123) ==> True
452
- ```
453
+ ```
453
454
 
454
455
  #### test for divisibility
455
456
 
@@ -466,7 +467,6 @@ It is also possible to test for divisibility of an ordinary int:
466
467
  istr.is_divisible(18, 3) ==> True
467
468
  istr.is_divisible(19, 3) ==> False
468
469
  ```
469
- ```
470
470
  #### test for square
471
471
 
472
472
  It is possible to test whether the value is a perfect square (provided the istr can be interpreted as an int) with the `is_square` method, e.g.
@@ -763,11 +763,11 @@ istr.count(10,3) ==> istr('10'), istr('13'), istr('16'), ...
763
763
  #### istr.zip
764
764
 
765
765
  The class method `istr.zip` is the equivalent of the zip builtin, but applies istr to each element. `istr.zip` also supports the join parameter:
766
- ```
766
+ ```
767
767
  print(list(istr.zip('12', '345')))
768
768
  print(list(istr.zip('12', '345', join=True)))
769
769
  print(list(istr.zip('12', '345', strict=True)))
770
- ```
770
+ ```
771
771
  results in
772
772
  ```
773
773
  [(istr('1'), istr('3')), (istr('2'), istr('4'))]
@@ -781,11 +781,11 @@ to `istr` and then concatenate these.
781
781
 
782
782
  `
783
783
 
784
- ```
784
+ ```
785
785
  list(istr.concat(((1,2),(3,4))) ==> istr([12,34])
786
786
  list(istr.concat(istr.permutations(range(3),2))) ==>
787
787
  [istr('01'), istr('02'), istr('10'), istr('12'), istr('20'), istr('21')]
788
- ```
788
+ ```
789
789
 
790
790
  #### prod to get product of an iterable
791
791
 
@@ -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) ==> 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 an str. E.g.:
847
+ This method can also be used with a str. E.g.:
838
848
  ```
839
- istr.getitem('1234', 2) ==> 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')
@@ -1115,29 +1125,29 @@ operator/function int str Example
1115
1125
  + x istr(20) + 3 ==> istr('23')
1116
1126
  _ x istr(20) - 3 ==> istr('17')
1117
1127
  * x istr(20) * 3 ==> istr('60')
1118
- / x istr(20) / 3 ==> istr('6')
1119
- // x istr(20) // 3 ==> istr('6')
1120
- % x istr(20) % 3 ==> istr('2')
1121
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1122
- ** x istr(2) ** 3 ==> istr('8')
1123
- <=, <, >, >= x istr('100') > istr('2') ==> True
1124
- abs x abs(istr(-20)) ==> istr('20')
1125
- int x int(istr("20")) ==> 20
1126
- float x float(istr("20")) ==> 20.0
1127
- complex x complex(istr("20")) ==> (20+0j)
1128
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1129
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1130
- @ x istr(20) @ 3 ==> istr('202020')
1131
- | x istr(20) | '5' ==> istr('205')
1132
- slicing x istr(12345)[1:3] ==> istr('23')
1133
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1134
- len x len(istr(' 20 ')) ==> 4
1135
- count x istr(100).count(0) ==> 2
1128
+ / x istr(20) / 3 ==> istr('6')
1129
+ // x istr(20) // 3 ==> istr('6')
1130
+ % x istr(20) % 3 ==> istr('2')
1131
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1132
+ ** x istr(2) ** 3 ==> istr('8')
1133
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1134
+ abs x abs(istr(-20)) ==> istr('20')
1135
+ int x int(istr("20")) ==> 20
1136
+ float x float(istr("20")) ==> 20.0
1137
+ complex x complex(istr("20")) ==> (20+0j)
1138
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1139
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1140
+ @ x istr(20) @ 3 ==> istr('202020')
1141
+ | x istr(20) | '5' ==> istr('205')
1142
+ slicing x istr(12345)[1:3] ==> istr('23')
1143
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1144
+ len x len(istr(' 20 ')) ==> 4
1145
+ count x istr(100).count(0) ==> 2
1136
1146
  istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1137
- index x istr(' 100 ').index('0') ==> 2
1138
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1139
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1140
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1147
+ index x istr(' 100 ').index('0') ==> 2
1148
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1149
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1150
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1141
1151
  istr('aAbBcC').islower() ==> False
1142
1152
  istr(' abc ').strip() ==> istr('abc')
1143
1153
  ...
@@ -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.35.post0"
13
+ version = "1.1.37"
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():