Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2020-03-08 18:40:25 +0100
committerArthur de Jong <arthur@arthurdejong.org>2020-03-08 18:40:25 +0100
commitd09ed521f68c60c7a28948c5fcbf9faa4fcc073e (patch)
tree70f9cfbc05e826542af50523dcb73cf915e8eec5 /stdnum
parent60139a8f862f8a40bed2ed746c4402366f238aff (diff)
Use zip() for applying weights in check algorithms
Diffstat (limited to 'stdnum')
-rw-r--r--stdnum/lv/pvn.py2
-rw-r--r--stdnum/ru/inn.py9
2 files changed, 4 insertions, 7 deletions
diff --git a/stdnum/lv/pvn.py b/stdnum/lv/pvn.py
index 03db0f4..006b5c0 100644
--- a/stdnum/lv/pvn.py
+++ b/stdnum/lv/pvn.py
@@ -70,7 +70,7 @@ def calc_check_digit_pers(number):
should not have the check digit included."""
# note that this algorithm has not been confirmed by an independent source
weights = (10, 5, 8, 4, 2, 1, 6, 3, 7, 9)
- check = 1 + sum(weights[i] * int(n) for i, n in enumerate(number))
+ check = 1 + sum(w * int(n) for w, n in zip(weights, number))
return str(check % 11 % 10)
diff --git a/stdnum/ru/inn.py b/stdnum/ru/inn.py
index db30806..58cc216 100644
--- a/stdnum/ru/inn.py
+++ b/stdnum/ru/inn.py
@@ -51,18 +51,15 @@ def compact(number):
def calc_company_check_digit(number):
"""Calculate the check digit for the 10-digit ИНН for organisations."""
weights = (2, 4, 10, 3, 5, 9, 4, 6, 8)
- return str(sum(weights[i] * int(n)
- for i, n in enumerate(number[:9])) % 11 % 10)
+ return str(sum(w * int(n) for w, n in zip(weights, number)) % 11 % 10)
def calc_personal_check_digits(number):
"""Calculate the check digits for the 12-digit personal ИНН."""
weights = (7, 2, 4, 10, 3, 5, 9, 4, 6, 8)
- d1 = str(sum(weights[i] * int(n)
- for i, n in enumerate(number[:10])) % 11 % 10)
+ d1 = str(sum(w * int(n) for w, n in zip(weights, number)) % 11 % 10)
weights = (3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8)
- d2 = str(sum(weights[i] * int(n)
- for i, n in enumerate(number[:10] + d1)) % 11 % 10)
+ d2 = str(sum(w * int(n) for w, n in zip(weights, number[:10] + d1)) % 11 % 10)
return d1 + d2