lists.arthurdejong.org
RSS feed

python-stdnum commit: r34 - in python-stdnum/stdnum: . isbn

[Date Prev][Date Next] [Thread Prev][Thread Next]

python-stdnum commit: r34 - in python-stdnum/stdnum: . isbn



Author: arthur
Date: Thu Aug 26 23:03:44 2010
New Revision: 34
URL: http://arthurdejong.org/viewvc/python-stdnum?view=rev&revision=34

Log:
switch to using enumerate() for looping over numbers where needed

Modified:
   python-stdnum/stdnum/isbn/__init__.py
   python-stdnum/stdnum/ismn.py
   python-stdnum/stdnum/issn.py
   python-stdnum/stdnum/verhoeff.py

Modified: python-stdnum/stdnum/isbn/__init__.py
==============================================================================
--- python-stdnum/stdnum/isbn/__init__.py       Sat Aug 21 17:37:27 2010        
(r33)
+++ python-stdnum/stdnum/isbn/__init__.py       Thu Aug 26 23:03:44 2010        
(r34)
@@ -51,13 +51,13 @@
 def _calc_isbn10_check_digit(number):
     """Calculate the ISBN check digit for 10-digit numbers. The number passed
     should not have the check bit included."""
-    check = sum( (i + 1) * int(number[i]) for i in range(len(number)) ) % 11
+    check = sum( (i + 1) * int(n) for i, n in enumerate(number) ) % 11
     return 'X' if check == 10 else str(check)
 
 def _calc_isbn13_check_digit(number):
     """Calculate the ISBN check digit for 13-digit numbers. The number passed
     should not have the check bit included."""
-    return str((10 - sum( (2 * (i % 2) + 1) * int(number[i]) for i in 
range(len(number)))) % 10)
+    return str((10 - sum( (2 * (i % 2) + 1) * int(n) for i, n in 
enumerate(number))) % 10)
 
 def isbn_type(number):
     """Check the passed number and returns 'ISBN13', 'ISBN10' or None (for

Modified: python-stdnum/stdnum/ismn.py
==============================================================================
--- python-stdnum/stdnum/ismn.py        Sat Aug 21 17:37:27 2010        (r33)
+++ python-stdnum/stdnum/ismn.py        Thu Aug 26 23:03:44 2010        (r34)
@@ -48,7 +48,7 @@
 def _calc_check_digit(number):
     """Calculate the ISMN check digit. The number passed should not have
     the check bit included and should be in the 13-digit form."""
-    return str((10 - sum( (2 * (i % 2) + 1) * int(number[i]) for i in 
range(len(number)))) % 10)
+    return str((10 - sum( (2 * (i % 2) + 1) * int(n) for i, n in 
enumerate(number))) % 10)
 
 def is_valid(number):
     """Checks to see if the number provided is a valid ISMN (either a legacy

Modified: python-stdnum/stdnum/issn.py
==============================================================================
--- python-stdnum/stdnum/issn.py        Sat Aug 21 17:37:27 2010        (r33)
+++ python-stdnum/stdnum/issn.py        Thu Aug 26 23:03:44 2010        (r34)
@@ -40,7 +40,7 @@
 def _calc_check_digit(number):
     """Calculate the ISSN check digit for 10-digit numbers. The number passed
     should not have the check bit included."""
-    check = (11 - sum( (8 - i) * int(number[i]) for i in range(len(number)) ) 
) % 11
+    check = (11 - sum( (8 - i) * int(n) for i, n in enumerate(number) ) ) % 11
     return 'X' if check == 10 else str(check)
 
 def is_valid(number):

Modified: python-stdnum/stdnum/verhoeff.py
==============================================================================
--- python-stdnum/stdnum/verhoeff.py    Sat Aug 21 17:37:27 2010        (r33)
+++ python-stdnum/stdnum/verhoeff.py    Thu Aug 26 23:03:44 2010        (r34)
@@ -66,8 +66,8 @@
     number = tuple( int(n) for n in reversed(str(number)) )
     # calculate checksum
     check = 0
-    for i in range(len(number)):
-        check = _multiplication_table[check][_permutation_table[i % 
8][number[i]]]
+    for i, n in enumerate(number):
+        check = _multiplication_table[check][_permutation_table[i % 8][n]]
     return check
 
 def is_valid(number):
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits