istr-python 1.1.44__tar.gz → 1.2.0__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.44
3
+ Version: 1.2.0
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
@@ -339,17 +339,16 @@ several other types:
339
339
  istr({0, 1, 4}) ==> {istr('4'), istr('0'), istr('1')} # or similar
340
340
  ```
341
341
 
342
- - if a range, an istr.range instance will be returned
342
+ - if a range, a generator that yields istr-s will be returned
343
343
 
344
344
  ```
345
- istr(range(3)) ==> istr.range(3)
346
- list(istr(range(3))) ==> [istr('0'), istr('1'), istr('2')]
347
- len(istr(range(3))) ==> 3
345
+ list(istr(range(3))) ==> [istr('0', istr('1', istr('2')]
346
+
348
347
  ```
349
348
 
350
- - if an istr.range instance, the same istr.range will be returned
349
+ - if an istr.range instance, the generator will be propagated
351
350
  ```
352
- istr(istr.range(5)) ==> istr.range(5)
351
+ list(istr(istr.range(3))) ==> [istr('0', istr('1', istr('2')]
353
352
  ```
354
353
 
355
354
 
@@ -370,14 +369,29 @@ a, b, c = istr(*range(3)) ==> a=istr('0') , b=istr('1'), c=istr('2')
370
369
  ```
371
370
  #### Alternative way of range specification
372
371
 
373
- Instead of `istr(range(..))` it is possible to use `istr,range(..)` instead, like
372
+ Instead of `istr(range(..))` it is possible to use `istr.range(..)` instead, like
374
373
 
375
374
  `list(istr.range(3,6))` ==> `[istr('3'), istr('4'), istr('5')]`
376
375
 
377
- In contrast to the builtin `range`, `istr.range` supports a non keyword parameter `length`:
376
+ In contrast to the builtin `range`, `istr.range` supports a keyword parameter `length`:
378
377
 
379
378
  `list(istr.range(length=3))` is equivalent to `istr.range(100, 1000)`
380
379
 
380
+ On top of this, `istr.range` support a keyword parameter `distinct`, to return a generator that yields only numbers with distinct numbers:
381
+
382
+ `list(istr.range(98,104,distinct=True))` is `[istr('98'), istr('102'), istr('103')]`
383
+
384
+ For `istr.range(length=..., distict=True)` the generation is optimized (not just checking each possible value).
385
+
386
+ It is also possible to specify an exclude parameter, with which any generated value will be discarded if it contains a character in exclude. E.g:
387
+
388
+ ```
389
+ for i in istr.range(length=5, distinct=True):
390
+ if ...:
391
+ for j in istr.range(length=2, distinct=True, exclude=i):
392
+ ...
393
+ ```
394
+
381
395
  #### square root, cubic root and nth root
382
396
  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
397
  ```
@@ -547,15 +561,15 @@ istr.divisors(18, False) ==> [istr('1'), istr('18'), istr('2'), istr('9'), istr(
547
561
 
548
562
  #### test whether all characters are distinct
549
563
 
550
- With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
564
+ With the `is_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
551
565
 
552
566
  ```
553
- istr('01234').all_distict() ==> True
554
- istr('012340').all_distict() ==> False
567
+ istr('01234').is_distict() ==> True
568
+ istr('012340').is_distict() ==> False
555
569
  n98 = istr(98)
556
570
  n100 = n98 + 2
557
- istr(n98).all_distinct() ==> True
558
- istr(n100).all_distinct() ==> False
571
+ istr(n98).is_distinct() ==> True
572
+ istr(n100).is_distinct() ==> False
559
573
  ```
560
574
  #### test if characters are consecutive
561
575
 
@@ -824,8 +838,17 @@ Alternatively, it is possible to get a list of all squares, cubes, power_ofs or
824
838
 
825
839
  `istr.squares (length=2)` returns a list of all squares of length 2, so between 10 and 99.
826
840
 
841
+ If the keyword `distinct` is True, all values that are not distinct, will be excluded, like:
842
+
843
+ `list(istr.primes(list(istr.primes(100,132,distinct=True))` is `[istr('103'), istr('107'), istr('109'), istr('127')]`, thus leaving out 101, 113 and 131
844
+
827
845
  Unless `cache=False` is specified, the query result is cached.
828
846
 
847
+ #### filter distinct_only
848
+
849
+ With `istr.distinct_only` any iterable can skip values that are not distinct:
850
+ `list(istr.distinct_only([10, 11, 100, 123, 'abc', 'aaa']))` is `[istr('10'), istr('123'), istr('abc')]`
851
+
829
852
  #### Safe indexing (getitem)
830
853
 
831
854
  The `istr.getitem` method is essentially, a safe version of indexing an istr.
@@ -1127,11 +1150,8 @@ This will print
1127
1150
  ?
1128
1151
  ```
1129
1152
 
1130
- ##### Note
1131
1153
  >
1132
- > The way an `istr` is represented is determined at initialization.
1133
-
1134
- It is also possible to set the repr mode without a context manager:
1154
+ > It is also possible to set the repr mode without a context manager:
1135
1155
 
1136
1156
  ```
1137
1157
  istr.repr_mode('str')
@@ -1148,48 +1168,6 @@ print(repr(istr.repr_mode()))
1148
1168
  ```
1149
1169
  will output `istr`.
1150
1170
 
1151
- #### Changing the base system
1152
-
1153
- By default, `istr` works in base 10. However it is possible to change the base system with the `istr.base()` context manager / method.
1154
-
1155
- Any base between 2 and 36 may be used.
1156
-
1157
- Note that the integer is **always** stored in base 10 mode, but the string
1158
- representation will reflect the chosen base (at time of initialization).
1159
-
1160
- Some examples:
1161
- ```
1162
- with istr.base(16):
1163
- a = istr('7fff')
1164
- print(int(a))
1165
-
1166
- b = istr(127)
1167
- print(repr(b))
1168
- ```
1169
- This will result in
1170
- ```
1171
- 32767
1172
- istr('7F')
1173
- ```
1174
- All calculations are done in the decimal 10 base system.
1175
-
1176
- Note that the way an `istr` is interpreted is determined at initialization.
1177
-
1178
- It is also possible to set the repr mode without a context manager:
1179
- ```
1180
- istr.base(16)
1181
- print(int(istr('7fff')))
1182
- ```
1183
- This will print
1184
- ```
1185
- 32767
1186
- ```
1187
- Finally, the current base can be queried with `istr.base()`, so upon start:
1188
- ```
1189
- print(istr.base())
1190
- ```
1191
- will result in `10`.
1192
-
1193
1171
  #### Changing the format of the string
1194
1172
 
1195
1173
  When an istr is initialized with a string the istr will be always stored as such.
@@ -1240,9 +1218,8 @@ istr('123')
1240
1218
  istr('1234')
1241
1219
  ```
1242
1220
 
1243
- ##### Note
1244
- >
1245
- > For bases other than 10, the string will never be reformatted!
1221
+
1222
+
1246
1223
 
1247
1224
  ### Overview of operations
1248
1225
 
@@ -1254,32 +1231,31 @@ operator/function int str Example
1254
1231
  + x istr(20) + 3 ==> istr('23')
1255
1232
  _ x istr(20) - 3 ==> istr('17')
1256
1233
  * x istr(20) * 3 ==> istr('60')
1257
- / x istr(20) / 3 ==> istr('6')
1258
- // x istr(20) // 3 ==> istr('6')
1259
- % x istr(20) % 3 ==> istr('2')
1260
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1261
- ** x istr(2) ** 3 ==> istr('8')
1262
- <=, <, >, >= x istr('100') > istr('2') ==> True
1263
- abs x abs(istr(-20)) ==> istr('20')
1264
- int x int(istr("20")) ==> 20
1265
- float x float(istr("20")) ==> 20.0
1266
- complex x complex(istr("20")) ==> (20+0j)
1267
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1268
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1269
- @ x istr(20) @ 3 ==> istr('202020')
1270
- | x istr(20) | '5' ==> istr('205')
1271
- slicing x istr(12345)[1:3] ==> istr('23')
1272
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1273
- len x len(istr(' 20 ')) ==> 4
1274
- count x istr(100).count(0) ==> 2
1275
- istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1276
- index x istr(' 100 ').index('0') ==> 2
1277
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1278
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1279
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1234
+ / x istr(20) / 3 ==> istr('6')
1235
+ // x istr(20) // 3 ==> istr('6')
1236
+ % x istr(20) % 3 ==> istr('2')
1237
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1238
+ ** x istr(2) ** 3 ==> istr('8')
1239
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1240
+ abs x abs(istr(-20)) ==> istr('20')
1241
+ int x int(istr("20")) ==> 20
1242
+ float x float(istr("20")) ==> 20.0
1243
+ complex x complex(istr("20")) ==> (20+0j)
1244
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1245
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1246
+ @ x istr(20) @ 3 ==> istr('202020')
1247
+ | x istr(20) | '5' ==> istr('205')
1248
+ slicing x istr(12345)[1:3] ==> istr('23')
1249
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1250
+ len x len(istr(' 20 ')) ==> 4
1251
+ count x istr(100).count(0) ==> 2
1252
+ istr.count(100) ==> istr('100'), istr('101'). ...
1253
+ index x istr(' 100 ').index('0') ==> 2
1254
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1255
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1256
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1280
1257
  istr('aAbBcC').islower() ==> False
1281
1258
  istr(' abc ').strip() ==> istr('abc')
1282
- ...
1283
1259
  -----------------------------------------------------------------------------------------
1284
1260
  *) str is applied if is_int() is False
1285
1261
  ```
@@ -326,17 +326,16 @@ several other types:
326
326
  istr({0, 1, 4}) ==> {istr('4'), istr('0'), istr('1')} # or similar
327
327
  ```
328
328
 
329
- - if a range, an istr.range instance will be returned
329
+ - if a range, a generator that yields istr-s will be returned
330
330
 
331
331
  ```
332
- istr(range(3)) ==> istr.range(3)
333
- list(istr(range(3))) ==> [istr('0'), istr('1'), istr('2')]
334
- len(istr(range(3))) ==> 3
332
+ list(istr(range(3))) ==> [istr('0', istr('1', istr('2')]
333
+
335
334
  ```
336
335
 
337
- - if an istr.range instance, the same istr.range will be returned
336
+ - if an istr.range instance, the generator will be propagated
338
337
  ```
339
- istr(istr.range(5)) ==> istr.range(5)
338
+ list(istr(istr.range(3))) ==> [istr('0', istr('1', istr('2')]
340
339
  ```
341
340
 
342
341
 
@@ -357,14 +356,29 @@ a, b, c = istr(*range(3)) ==> a=istr('0') , b=istr('1'), c=istr('2')
357
356
  ```
358
357
  #### Alternative way of range specification
359
358
 
360
- Instead of `istr(range(..))` it is possible to use `istr,range(..)` instead, like
359
+ Instead of `istr(range(..))` it is possible to use `istr.range(..)` instead, like
361
360
 
362
361
  `list(istr.range(3,6))` ==> `[istr('3'), istr('4'), istr('5')]`
363
362
 
364
- In contrast to the builtin `range`, `istr.range` supports a non keyword parameter `length`:
363
+ In contrast to the builtin `range`, `istr.range` supports a keyword parameter `length`:
365
364
 
366
365
  `list(istr.range(length=3))` is equivalent to `istr.range(100, 1000)`
367
366
 
367
+ On top of this, `istr.range` support a keyword parameter `distinct`, to return a generator that yields only numbers with distinct numbers:
368
+
369
+ `list(istr.range(98,104,distinct=True))` is `[istr('98'), istr('102'), istr('103')]`
370
+
371
+ For `istr.range(length=..., distict=True)` the generation is optimized (not just checking each possible value).
372
+
373
+ It is also possible to specify an exclude parameter, with which any generated value will be discarded if it contains a character in exclude. E.g:
374
+
375
+ ```
376
+ for i in istr.range(length=5, distinct=True):
377
+ if ...:
378
+ for j in istr.range(length=2, distinct=True, exclude=i):
379
+ ...
380
+ ```
381
+
368
382
  #### square root, cubic root and nth root
369
383
  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
384
  ```
@@ -534,15 +548,15 @@ istr.divisors(18, False) ==> [istr('1'), istr('18'), istr('2'), istr('9'), istr(
534
548
 
535
549
  #### test whether all characters are distinct
536
550
 
537
- With the `all_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
551
+ With the `is_distinct` method, it is possible to test whether all characters are distinct (i.e. no character appears more than once).
538
552
 
539
553
  ```
540
- istr('01234').all_distict() ==> True
541
- istr('012340').all_distict() ==> False
554
+ istr('01234').is_distict() ==> True
555
+ istr('012340').is_distict() ==> False
542
556
  n98 = istr(98)
543
557
  n100 = n98 + 2
544
- istr(n98).all_distinct() ==> True
545
- istr(n100).all_distinct() ==> False
558
+ istr(n98).is_distinct() ==> True
559
+ istr(n100).is_distinct() ==> False
546
560
  ```
547
561
  #### test if characters are consecutive
548
562
 
@@ -811,8 +825,17 @@ Alternatively, it is possible to get a list of all squares, cubes, power_ofs or
811
825
 
812
826
  `istr.squares (length=2)` returns a list of all squares of length 2, so between 10 and 99.
813
827
 
828
+ If the keyword `distinct` is True, all values that are not distinct, will be excluded, like:
829
+
830
+ `list(istr.primes(list(istr.primes(100,132,distinct=True))` is `[istr('103'), istr('107'), istr('109'), istr('127')]`, thus leaving out 101, 113 and 131
831
+
814
832
  Unless `cache=False` is specified, the query result is cached.
815
833
 
834
+ #### filter distinct_only
835
+
836
+ With `istr.distinct_only` any iterable can skip values that are not distinct:
837
+ `list(istr.distinct_only([10, 11, 100, 123, 'abc', 'aaa']))` is `[istr('10'), istr('123'), istr('abc')]`
838
+
816
839
  #### Safe indexing (getitem)
817
840
 
818
841
  The `istr.getitem` method is essentially, a safe version of indexing an istr.
@@ -1114,11 +1137,8 @@ This will print
1114
1137
  ?
1115
1138
  ```
1116
1139
 
1117
- ##### Note
1118
1140
  >
1119
- > The way an `istr` is represented is determined at initialization.
1120
-
1121
- It is also possible to set the repr mode without a context manager:
1141
+ > It is also possible to set the repr mode without a context manager:
1122
1142
 
1123
1143
  ```
1124
1144
  istr.repr_mode('str')
@@ -1135,48 +1155,6 @@ print(repr(istr.repr_mode()))
1135
1155
  ```
1136
1156
  will output `istr`.
1137
1157
 
1138
- #### Changing the base system
1139
-
1140
- By default, `istr` works in base 10. However it is possible to change the base system with the `istr.base()` context manager / method.
1141
-
1142
- Any base between 2 and 36 may be used.
1143
-
1144
- Note that the integer is **always** stored in base 10 mode, but the string
1145
- representation will reflect the chosen base (at time of initialization).
1146
-
1147
- Some examples:
1148
- ```
1149
- with istr.base(16):
1150
- a = istr('7fff')
1151
- print(int(a))
1152
-
1153
- b = istr(127)
1154
- print(repr(b))
1155
- ```
1156
- This will result in
1157
- ```
1158
- 32767
1159
- istr('7F')
1160
- ```
1161
- All calculations are done in the decimal 10 base system.
1162
-
1163
- Note that the way an `istr` is interpreted is determined at initialization.
1164
-
1165
- It is also possible to set the repr mode without a context manager:
1166
- ```
1167
- istr.base(16)
1168
- print(int(istr('7fff')))
1169
- ```
1170
- This will print
1171
- ```
1172
- 32767
1173
- ```
1174
- Finally, the current base can be queried with `istr.base()`, so upon start:
1175
- ```
1176
- print(istr.base())
1177
- ```
1178
- will result in `10`.
1179
-
1180
1158
  #### Changing the format of the string
1181
1159
 
1182
1160
  When an istr is initialized with a string the istr will be always stored as such.
@@ -1227,9 +1205,8 @@ istr('123')
1227
1205
  istr('1234')
1228
1206
  ```
1229
1207
 
1230
- ##### Note
1231
- >
1232
- > For bases other than 10, the string will never be reformatted!
1208
+
1209
+
1233
1210
 
1234
1211
  ### Overview of operations
1235
1212
 
@@ -1241,32 +1218,31 @@ operator/function int str Example
1241
1218
  + x istr(20) + 3 ==> istr('23')
1242
1219
  _ x istr(20) - 3 ==> istr('17')
1243
1220
  * x istr(20) * 3 ==> istr('60')
1244
- / x istr(20) / 3 ==> istr('6')
1245
- // x istr(20) // 3 ==> istr('6')
1246
- % x istr(20) % 3 ==> istr('2')
1247
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1248
- ** x istr(2) ** 3 ==> istr('8')
1249
- <=, <, >, >= x istr('100') > istr('2') ==> True
1250
- abs x abs(istr(-20)) ==> istr('20')
1251
- int x int(istr("20")) ==> 20
1252
- float x float(istr("20")) ==> 20.0
1253
- complex x complex(istr("20")) ==> (20+0j)
1254
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1255
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1256
- @ x istr(20) @ 3 ==> istr('202020')
1257
- | x istr(20) | '5' ==> istr('205')
1258
- slicing x istr(12345)[1:3] ==> istr('23')
1259
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1260
- len x len(istr(' 20 ')) ==> 4
1261
- count x istr(100).count(0) ==> 2
1262
- istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1263
- index x istr(' 100 ').index('0') ==> 2
1264
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1265
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1266
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1221
+ / x istr(20) / 3 ==> istr('6')
1222
+ // x istr(20) // 3 ==> istr('6')
1223
+ % x istr(20) % 3 ==> istr('2')
1224
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1225
+ ** x istr(2) ** 3 ==> istr('8')
1226
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1227
+ abs x abs(istr(-20)) ==> istr('20')
1228
+ int x int(istr("20")) ==> 20
1229
+ float x float(istr("20")) ==> 20.0
1230
+ complex x complex(istr("20")) ==> (20+0j)
1231
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1232
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1233
+ @ x istr(20) @ 3 ==> istr('202020')
1234
+ | x istr(20) | '5' ==> istr('205')
1235
+ slicing x istr(12345)[1:3] ==> istr('23')
1236
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1237
+ len x len(istr(' 20 ')) ==> 4
1238
+ count x istr(100).count(0) ==> 2
1239
+ istr.count(100) ==> istr('100'), istr('101'). ...
1240
+ index x istr(' 100 ').index('0') ==> 2
1241
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1242
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1243
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1267
1244
  istr('aAbBcC').islower() ==> False
1268
1245
  istr(' abc ').strip() ==> istr('abc')
1269
- ...
1270
1246
  -----------------------------------------------------------------------------------------
1271
1247
  *) str is applied if is_int() is False
1272
1248
  ```