python-stdnum commit: r113 - python-stdnum/stdnum
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
python-stdnum commit: r113 - python-stdnum/stdnum
- From: Commits of the python-stdnum project <python-stdnum-commits [at] lists.arthurdejong.org>
- To: python-stdnum-commits [at] lists.arthurdejong.org
- Reply-to: python-stdnum-users [at] lists.arthurdejong.org
- Subject: python-stdnum commit: r113 - python-stdnum/stdnum
- Date: Sat, 11 Feb 2012 15:43:56 +0100 (CET)
Author: arthur
Date: Sat Feb 11 15:43:55 2012
New Revision: 113
URL: http://arthurdejong.org/viewvc/python-stdnum?revision=113&view=revision
Log:
implement a digitsum() function to find the sub of all digits in a number
Modified:
python-stdnum/stdnum/util.py
Modified: python-stdnum/stdnum/util.py
==============================================================================
--- python-stdnum/stdnum/util.py Sat Feb 11 15:37:28 2012 (r112)
+++ python-stdnum/stdnum/util.py Sat Feb 11 15:43:55 2012 (r113)
@@ -17,13 +17,23 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
-"""Common functions for other stdnum modules.
-
->>> clean('123-456:78 9', ' -:')
-'123456789'
-"""
+"""Common functions for other stdnum modules."""
def clean(number, deletechars):
- """Remove the specified characters from the supplied number."""
+ """Remove the specified characters from the supplied number.
+
+ >>> clean('123-456:78 9', ' -:')
+ '123456789'
+ """
return ''.join(x for x in number if x not in deletechars)
+
+
+def digitsum(numbers):
+ """Returns the sum of the individual digits of the provided numbers.
+
+ >>> digitsum([12, 55])
+ 13
+ """
+ # note: this only works for two-digit numbers
+ return sum((x // 10) + (x % 10) for x in numbers)
--
To unsubscribe send an email to
python-stdnum-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/python-stdnum-commits/
- python-stdnum commit: r113 - python-stdnum/stdnum,
Commits of the python-stdnum project