From 7493eca08309922c76974566cc6d2eee1de126e1 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 7 Apr 2017 15:27:48 +0200 Subject: Use a slightly more readable weight alternation Switch to a slightly more readable syntax for alternating between two weights in checksums calculations. --- stdnum/ean.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'stdnum/ean.py') 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) -- cgit v1.2.3