istr-python 1.1.26__tar.gz → 1.1.27__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.26 → istr_python-1.1.27}/PKG-INFO +17 -5
- {istr_python-1.1.26 → istr_python-1.1.27}/README.md +16 -4
- {istr_python-1.1.26 → istr_python-1.1.27}/istr/istr.py +11 -4
- {istr_python-1.1.26 → istr_python-1.1.27}/istr_python.egg-info/PKG-INFO +17 -5
- {istr_python-1.1.26 → istr_python-1.1.27}/pyproject.toml +1 -1
- {istr_python-1.1.26 → istr_python-1.1.27}/tests/test_istr.py +20 -8
- {istr_python-1.1.26 → istr_python-1.1.27}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.26 → istr_python-1.1.27}/istr/__init__.py +0 -0
- {istr_python-1.1.26 → istr_python-1.1.27}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.26 → istr_python-1.1.27}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.26 → istr_python-1.1.27}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.26 → istr_python-1.1.27}/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.27
|
|
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
|
|
@@ -611,6 +611,18 @@ results in
|
|
|
611
611
|
(istr('2'), istr('1'), istr('0'))
|
|
612
612
|
```
|
|
613
613
|
|
|
614
|
+
Note that the count method is also used like `istr(100).find(0)` , using the count method of strings. The context defines which version is used:
|
|
615
|
+
|
|
616
|
+
```
|
|
617
|
+
istr(100).count(0) ==> 2
|
|
618
|
+
istr(100).count(0, 1) ==>2
|
|
619
|
+
istr(100).count("a") ==> 0
|
|
620
|
+
|
|
621
|
+
istr.count() ==> istr('0'), istr('1'), istr('2'), ...
|
|
622
|
+
istr.count(10) ==> istr('10'), istr('11'), istr('12'), ...
|
|
623
|
+
istr.count(10,3) ==> istr('10'), istr('13'), istr('16'), ...
|
|
624
|
+
```
|
|
625
|
+
|
|
614
626
|
#### concatenate an iterable
|
|
615
627
|
|
|
616
628
|
The `istr.concat` method can be useful to map all items of an iterable
|
|
@@ -938,14 +950,14 @@ _ x istr(20) - 3 ==> istr('17')
|
|
|
938
950
|
slicing x istr(12345)[1:3] ==> istr('23')
|
|
939
951
|
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
940
952
|
len x len(istr(' 20 ')) ==> 4
|
|
941
|
-
count x istr(100).count(
|
|
953
|
+
count x istr(100).count(0) ==> 2
|
|
942
954
|
index x istr(' 100 ').index('0') ==> 2
|
|
943
955
|
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
944
956
|
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
945
957
|
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
958
|
+
istr('aAbBcC').islower() ==> False
|
|
959
|
+
istr(' abc ').strip() ==> istr('abc')
|
|
960
|
+
...
|
|
949
961
|
-----------------------------------------------------------------------------------------
|
|
950
962
|
*) str is applied if is_int() is False
|
|
951
963
|
```
|
|
@@ -598,6 +598,18 @@ results in
|
|
|
598
598
|
(istr('2'), istr('1'), istr('0'))
|
|
599
599
|
```
|
|
600
600
|
|
|
601
|
+
Note that the count method is also used like `istr(100).find(0)` , using the count method of strings. The context defines which version is used:
|
|
602
|
+
|
|
603
|
+
```
|
|
604
|
+
istr(100).count(0) ==> 2
|
|
605
|
+
istr(100).count(0, 1) ==>2
|
|
606
|
+
istr(100).count("a") ==> 0
|
|
607
|
+
|
|
608
|
+
istr.count() ==> istr('0'), istr('1'), istr('2'), ...
|
|
609
|
+
istr.count(10) ==> istr('10'), istr('11'), istr('12'), ...
|
|
610
|
+
istr.count(10,3) ==> istr('10'), istr('13'), istr('16'), ...
|
|
611
|
+
```
|
|
612
|
+
|
|
601
613
|
#### concatenate an iterable
|
|
602
614
|
|
|
603
615
|
The `istr.concat` method can be useful to map all items of an iterable
|
|
@@ -925,14 +937,14 @@ _ x istr(20) - 3 ==> istr('17')
|
|
|
925
937
|
slicing x istr(12345)[1:3] ==> istr('23')
|
|
926
938
|
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
927
939
|
len x len(istr(' 20 ')) ==> 4
|
|
928
|
-
count x istr(100).count(
|
|
940
|
+
count x istr(100).count(0) ==> 2
|
|
929
941
|
index x istr(' 100 ').index('0') ==> 2
|
|
930
942
|
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
931
943
|
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
932
944
|
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
945
|
+
istr('aAbBcC').islower() ==> False
|
|
946
|
+
istr(' abc ').strip() ==> istr('abc')
|
|
947
|
+
...
|
|
936
948
|
-----------------------------------------------------------------------------------------
|
|
937
949
|
*) str is applied if is_int() is False
|
|
938
950
|
```
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
8
|
+
__version__ = "1.1.27"
|
|
9
9
|
import functools
|
|
10
10
|
import itertools
|
|
11
11
|
import types
|
|
@@ -402,9 +402,10 @@ class istr(str):
|
|
|
402
402
|
|
|
403
403
|
def is_odd(self):
|
|
404
404
|
return not istr.is_divisible_by(self, 2)
|
|
405
|
-
|
|
405
|
+
|
|
406
406
|
def is_palindrome(self):
|
|
407
|
-
|
|
407
|
+
self_as_str = str(self)
|
|
408
|
+
return self_as_str == self_as_str[::-1]
|
|
408
409
|
|
|
409
410
|
def is_divisible_by(self, divisor):
|
|
410
411
|
return istr.divided_by(self, divisor) is not None
|
|
@@ -679,12 +680,18 @@ class istr(str):
|
|
|
679
680
|
return cls(getattr(itertools, name)(*args, **kwargs))
|
|
680
681
|
|
|
681
682
|
for name in dir(itertools):
|
|
682
|
-
if not name.startswith("__"):
|
|
683
|
+
if not name.startswith("__") and not name == "count": # count has its own method
|
|
683
684
|
if name in ("groupby", "tee"):
|
|
684
685
|
locals()[name] = getattr(itertools, name)
|
|
685
686
|
else:
|
|
686
687
|
locals()[name] = functools.partialmethod(_itertools_method, name)
|
|
687
688
|
|
|
689
|
+
def count(*args):
|
|
690
|
+
if len(args) >= 2 and isinstance(args[0], istr):
|
|
691
|
+
return str(args[0]).count(str(args[1]), *map(int, args[2:]))
|
|
692
|
+
else:
|
|
693
|
+
return istr(itertools.count(*args))
|
|
694
|
+
|
|
688
695
|
def is_int(self):
|
|
689
696
|
return self._as_int is not self._nan
|
|
690
697
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.27
|
|
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
|
|
@@ -611,6 +611,18 @@ results in
|
|
|
611
611
|
(istr('2'), istr('1'), istr('0'))
|
|
612
612
|
```
|
|
613
613
|
|
|
614
|
+
Note that the count method is also used like `istr(100).find(0)` , using the count method of strings. The context defines which version is used:
|
|
615
|
+
|
|
616
|
+
```
|
|
617
|
+
istr(100).count(0) ==> 2
|
|
618
|
+
istr(100).count(0, 1) ==>2
|
|
619
|
+
istr(100).count("a") ==> 0
|
|
620
|
+
|
|
621
|
+
istr.count() ==> istr('0'), istr('1'), istr('2'), ...
|
|
622
|
+
istr.count(10) ==> istr('10'), istr('11'), istr('12'), ...
|
|
623
|
+
istr.count(10,3) ==> istr('10'), istr('13'), istr('16'), ...
|
|
624
|
+
```
|
|
625
|
+
|
|
614
626
|
#### concatenate an iterable
|
|
615
627
|
|
|
616
628
|
The `istr.concat` method can be useful to map all items of an iterable
|
|
@@ -938,14 +950,14 @@ _ x istr(20) - 3 ==> istr('17')
|
|
|
938
950
|
slicing x istr(12345)[1:3] ==> istr('23')
|
|
939
951
|
iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
|
|
940
952
|
len x len(istr(' 20 ')) ==> 4
|
|
941
|
-
count x istr(100).count(
|
|
953
|
+
count x istr(100).count(0) ==> 2
|
|
942
954
|
index x istr(' 100 ').index('0') ==> 2
|
|
943
955
|
split x istr('1 2').split() ==> (istr('1'), istr('2'))
|
|
944
956
|
string format x f"|{istr(1234):6}|" ==> '|1234 |'
|
|
945
957
|
other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
958
|
+
istr('aAbBcC').islower() ==> False
|
|
959
|
+
istr(' abc ').strip() ==> istr('abc')
|
|
960
|
+
...
|
|
949
961
|
-----------------------------------------------------------------------------------------
|
|
950
962
|
*) str is applied if is_int() is False
|
|
951
963
|
```
|
|
@@ -254,14 +254,26 @@ def test_index():
|
|
|
254
254
|
one_to_twelve.index("13")
|
|
255
255
|
|
|
256
256
|
|
|
257
|
-
def
|
|
258
|
-
assert
|
|
259
|
-
assert
|
|
260
|
-
assert
|
|
261
|
-
assert
|
|
262
|
-
assert
|
|
263
|
-
assert
|
|
264
|
-
|
|
257
|
+
def test_str_count():
|
|
258
|
+
assert istr("100").count("0") == 2
|
|
259
|
+
assert istr("100").count("0",0) ==2
|
|
260
|
+
assert istr("100").count("0",1)==2
|
|
261
|
+
assert istr("100").count("0",2)==1
|
|
262
|
+
assert istr("100").count("0",0,1)==0
|
|
263
|
+
assert istr("100").count(0)==2
|
|
264
|
+
assert istr("100").count(10)==1
|
|
265
|
+
assert istr("100").count(100)==1
|
|
266
|
+
assert istr("1000").count(100)==1
|
|
267
|
+
assert isinstance(istr("100").count(),map) # this is in fact the itertools version
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def test_itertools_count():
|
|
271
|
+
assert list(itertools.islice(istr.count(),3))==[istr('0'), istr('1'), istr('2')]
|
|
272
|
+
assert list(istr.islice(istr.count(10),3)) ==[istr('10'), istr('11'), istr('12')]
|
|
273
|
+
assert list(istr.islice(istr.count(istr(10)),3)) ==[istr('10'), istr('11'), istr('12')]
|
|
274
|
+
assert list(istr.islice(istr.count(10,3),3))==[istr('10'), istr('13'), istr('16')]
|
|
275
|
+
|
|
276
|
+
assert istr.count(istr(10),1)==1 # this is in fact the istr version
|
|
265
277
|
|
|
266
278
|
def test_hash():
|
|
267
279
|
assert hash(istr.range(1, 13)) == hash(one_to_twelve)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|