Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum/ean.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2017-04-07 15:27:48 +0200
committerArthur de Jong <arthur@arthurdejong.org>2017-04-07 15:41:35 +0200
commit7493eca08309922c76974566cc6d2eee1de126e1 (patch)
tree2ba5847a44c3388ffc89f10a96bb1b37c2770b38 /stdnum/ean.py
parent23b2150c6ceee574207e0c5e5b19d2f95fbd9828 (diff)
Use a slightly more readable weight alternation
Switch to a slightly more readable syntax for alternating between two weights in checksums calculations.
Diffstat (limited to 'stdnum/ean.py')
-rw-r--r--stdnum/ean.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/stdnum/ean.py b/stdnum/ean.py
index ec6007e..c237f2e 100644
--- a/stdnum/ean.py
+++ b/stdnum/ean.py
@@ -1,6 +1,6 @@
# ean.py - functions for handling EANs
#
-# Copyright (C) 2011, 2012, 2013 Arthur de Jong
+# Copyright (C) 2011-2017 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -41,7 +41,7 @@ def compact(number):
def calc_check_digit(number):
"""Calculate the EAN check digit for 13-digit numbers. The number passed
should not have the check bit included."""
- return str((10 - sum((3 - 2 * (i % 2)) * int(n)
+ return str((10 - sum((3, 1)[i % 2] * int(n)
for i, n in enumerate(reversed(number)))) % 10)