istr-python 1.1.33__tar.gz → 1.1.34.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.33
3
+ Version: 1.1.34.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
@@ -435,18 +435,19 @@ It is also possible to test for divisibility of an ordinary int:
435
435
  istr.is_divisible(18, 3) ==> True
436
436
  istr.is_divisible(19, 3) ==> False
437
437
  ```
438
- The method `divided_by` not only tests divisibility, but also returns the result of the division. If not possible, None will be returned,
439
- 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('0')` 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.
440
441
  ```
441
442
  istr(18).divided_by(3) ==> 6 (actually istr("6"))
442
443
  istr(18).divided_by(istr(3)) ==> 6
443
- istr(19).divided_by(3) ==> None
444
- istr(19).divided_by(3, 0) ==> 0
445
- istr(19).divided_by(3) ==> None
446
- istr(19).divided_by(istr(3)) ==> None
444
+ istr(19).divided_by(3) ==> istr('0')
445
+ istr(19).divided_by(3, 1) ==> istr('1')
446
+ istr(19).divided_by(3) ==> istr('0')
447
+ istr(19).divided_by(istr(3)) ==> istr('0')
447
448
  istr.divided_by(18, 3) ==> 6
448
- istr.divided_by(19, 3) ==> None
449
- istr.divided_by(19, 3, 0) ==> 0
449
+ istr.divided_by(19, 3) ==> istr('0')
450
+ istr.divided_by(19, 3, 1) ==> istr('1')
450
451
  ```
451
452
  #### test for square
452
453
 
@@ -489,6 +490,14 @@ istr.is_power_of(81, 4) ==> True
489
490
  istr.is_power_of(82, 4) ==> False
490
491
  ```
491
492
 
493
+ If called without an exponent, the test will be for any perfect power:
494
+
495
+ ```
496
+ istr(2**10).is_power_of() ==> True
497
+ istr(-3**3).is_power_of() ==> True
498
+ istr(34).is_power_of() ==> False
499
+ ```
500
+
492
501
  #### test for prime
493
502
 
494
503
  It is possible to test whether the value is a prime number (provided the istr can be interpreted as an int) with the `is_prime` method, e.g.
@@ -503,6 +512,20 @@ It is also possible to test for prime of an ordinary int:
503
512
  istr.is_prime(4) ==> False
504
513
  istr.is_prime(5) ==> True
505
514
  ```
515
+ #### get divisors of a number
516
+ The method `divisors` will generate all divisors of a number.
517
+ Normally, the divisors are sorted, but if the sorted flag is False, the order is not necessarily maintained (this is slightly more efficient).
518
+ ```
519
+ istr(18).divisors() ==> [istr('1'), istr('2'), istr('3'), istr('6'), istr('9'), istr('18')]
520
+ istr(19).divisors() ==> [istr('1'), istr('19')]
521
+ istr(18).divisors(sorted=False) ==> [istr('1'), istr('18'), istr('2'), istr('9'), istr('3'), istr('6')]
522
+ ```
523
+ This method can also be used with an int. E.g.:
524
+ ```
525
+ istr.divisors(18) ==> [istr('1'), istr('2'), istr('3'), istr('6'), istr('9'), istr('18')]
526
+ istr.divisors(19) ==> [istr('1'), istr('19')]
527
+ istr.divisors(18, False) ==> [istr('1'), istr('18'), istr('2'), istr('9'), istr('3'), istr('6')]
528
+ ```
506
529
 
507
530
  #### test whether all characters are distinct
508
531
 
@@ -778,6 +801,31 @@ Alternatively, it is possible to get a list of all squares, cubes, power_ofs or
778
801
 
779
802
  Unless `cache=False` is specified, the query result is cached.
780
803
 
804
+ #### Safe indexing (getitem)
805
+
806
+ The `istr.getitem` method is essentially, a safe version of indexing an istr.
807
+ 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.
808
+
809
+ Note that the result will always be istr-ed, except when the result is None.
810
+
811
+ Examples:
812
+ ```
813
+ istr(1234).getitem(2) ==> 2
814
+ istr(1234).getitem(-2) ==> 3
815
+ istr(1234).getitem(5) ==> istr('')
816
+ istr(1234).getitem(5, '0') ==> istr('0')
817
+ istr(1234).getitem(5, None) ==> None
818
+ ```
819
+ This method can also be used with an str. E.g.:
820
+ ```
821
+ istr.getitem('1234', 2) ==> 2
822
+ istr.getitem('1234', -2) ==> 3
823
+ istr.getitem('1234', 5) ==> istr('')
824
+ istr.getitem('1234',5, '0') ==> istr('0')
825
+ istr.getitem('1234',5, None) ==> None
826
+ ```
827
+ Note that this method has the advantage that it can accept an istr as index, in contrast to normal indexing.
828
+
781
829
  #### generate istr with digits
782
830
 
783
831
  The class method `digits` can be used to return an istr of digits according to a given specification.