istr-python 1.1.32.post0__tar.gz → 1.1.34__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.32.post0
3
+ Version: 1.1.34
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
@@ -367,7 +367,18 @@ to unpack multiple values, e.g.
367
367
  a, b, c = istr(5, 6, 7) ==> a=istr('5') , b=istr('6'), c=istr('7')
368
368
  a, b, c = istr(*range(3)) ==> a=istr('0') , b=istr('1'), c=istr('2')
369
369
  ```
370
+ #### Alternative way of range specification
371
+
372
+ Instead of `istr(range(..))` it is possible to use `istr,range(..)` instead, like
373
+
374
+ `list(istr.range(3,6))` ==> `[istr('3'), istr('4'), istr('5')]`
375
+
376
+ In contrast to the builtin `range`, `istr.range` supports a non keyword parameter `length`:
377
+
378
+ `list(istr.range(length=3))` is equivalent to `istr.range(100, 1000)`
379
+
370
380
  #### test for even/odd
381
+
371
382
  It is possible to test for even/odd (provided the istr can be interpreted as an int) with the `is_even` and `is_odd` method, e.g.
372
383
 
373
384
  ```
@@ -424,18 +435,19 @@ It is also possible to test for divisibility of an ordinary int:
424
435
  istr.is_divisible(18, 3) ==> True
425
436
  istr.is_divisible(19, 3) ==> False
426
437
  ```
427
- The method `divided_by` not only tests divisibility, but also returns the result of the division. If not possible, None will be returned,
428
- unless the *fallback* (last argument) is given, in which case *fallback* will be returned.
438
+ The method `divided_by` not only tests divisibility, but also returns the result of the division. If not possible, `istr('')` will be returned, unless the *fallback* (last argument) is given, in which case *fallback* will be returned.
439
+
440
+ The result will be always istr-ed, except for None.
429
441
  ```
430
442
  istr(18).divided_by(3) ==> 6 (actually istr("6"))
431
443
  istr(18).divided_by(istr(3)) ==> 6
432
- istr(19).divided_by(3) ==> None
433
- istr(19).divided_by(3, 0) ==> 0
434
- istr(19).divided_by(3) ==> None
435
- istr(19).divided_by(istr(3)) ==> None
444
+ istr(19).divided_by(3) ==> istr('')
445
+ istr(19).divided_by(3, 0) ==> istr('0')
446
+ istr(19).divided_by(3) ==> istr('')
447
+ istr(19).divided_by(istr(3)) ==> istr('')
436
448
  istr.divided_by(18, 3) ==> 6
437
- istr.divided_by(19, 3) ==> None
438
- istr.divided_by(19, 3, 0) ==> 0
449
+ istr.divided_by(19, 3) ==> istr('')
450
+ istr.divided_by(19, 3, 0) ==> istr('0')
439
451
  ```
440
452
  #### test for square
441
453
 
@@ -754,15 +766,44 @@ In contrast to `math.sumprod()`, `istr.sumprod()` supports a `strict` parameter
754
766
  Thus, `istr.sumprod("12", (3,4,5), strict=False)` is `istr(11)`, whereas `istr.sumprod("12", (3,4,5))`
755
767
  raises a ValueError.
756
768
 
757
- #### get all squares, cubes, power ofs or primes in a given range
769
+ #### get all squares, cubes, power ofs or primes in a given range or with a given length
758
770
 
759
771
  The class methods `istr.squares`, `istr.cubes`, `istr.power_ofs` and `istr.primes` can be used to get a list of all squares, cubes, power_ofs or primes up to a given upperbound (non inclusive) or between a given lower bound and upper bound (non inclusive), like:
760
772
 
761
773
  `istr.squares (100)` returns a list of all squares <100
762
774
  `istr.squares(50, 100)` returns a list of all squares in the range [50, 100)
763
775
 
776
+ Alternatively, it is possible to get a list of all squares, cubes, power_ofs or primes with a given length, like:
777
+
778
+ `istr.squares (length=2)` returns a list of all squares of length 2, so between 10 and 99.
779
+
764
780
  Unless `cache=False` is specified, the query result is cached.
765
781
 
782
+ #### Safe indexing (getitem)
783
+
784
+ The `istr.getitem` method is essentially, a safe version of indexing an istr.
785
+ If the index is within the bounds of the istr, `getitem` just works like indexing. Otherwise, where normally an IndexError would be raised, the istr('') will be returned unless `fallback` (last argument) is specified.
786
+
787
+ Note that the result will always be istr-ed, except when the result is None.
788
+
789
+ Examples:
790
+ ```
791
+ istr(1234).getitem(2) ==> 2
792
+ istr(1234).getitem(-2) ==> 3
793
+ istr(1234).getitem(5) ==> istr('2')
794
+ istr(1234).getitem(5, '0') ==> istr('0')
795
+ istr(1234).getitem(5, None) ==> None
796
+ ```
797
+ This method can also be used with an str. E.g.:
798
+ ```
799
+ istr.getitem('1234', 2) ==> 2
800
+ istr.getitem('1234', -2) ==> 3
801
+ istr.getitem('1234', 5) ==> istr('2')
802
+ istr.getitem('1234',5, '0') ==> istr('0')
803
+ istr.getitem('1234',5, None) ==> None
804
+ ```
805
+ Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
806
+
766
807
  #### generate istr with digits
767
808
 
768
809
  The class method `digits` can be used to return an istr of digits according to a given specification.