Whilst browsing Rosetta Code, I came across a good algorithm for training students, SEDOL, so coded up a version in what I would call a very litteral translation of itsexplanation.
I changed the Python example on Wikipedia, as it did not have a validation function as other examples have, and added my code to the Rosetta page.
''' From: http://en.wikipedia.org/wiki/SEDOL SEDOLs are seven characters in length, consisting of two parts: a six-place alphanumeric code and a trailing check digit. ''' import string # constants sedolchars = string.digits + string.ascii_uppercase sedol2value = dict((ch, n) for n,ch in enumerate(sedolchars)) for ch in 'AEIOU': del sedol2value[ch] sedolchars = sorted(sedol2value.keys()) sedolweight = [1,3,1,7,3,9,1] def check(sedol): return len(sedol) == 7 and \  all(ch in sedolchars for ch in sedol) and \  sum(sedol2value[ch] * sedolweight[n] for n,ch in enumerate(sedol) ) % 10 == 0 def checksum(sedol):  tmp = sum(sedol2value[ch] * sedolweight[n] for n,ch in enumerate(sedol[:6]) ) return sedolchars[ (10 - (tmp % 10)) % 10] sedol = '0263494' print sedol, checksum(sedol) print # From: http://www.rosettacode.org/wiki/SEDOL for sedol in ''' 710889 B0YBKJ 406566 B0YBLH 228276 B0YBKL 557910 B0YBKR 585284 B0YBKT '''.split(): print sedol + checksum(sedol)Note:
I came back to the code after a few hours of sleep and thought initially that I would have trouble in the return statement of checksum() as I thought I would need a dictionary doing the full reverse matching of what sedol2value, from ints to characters. sedolchars nolonger includes the vowels so using that method for a value over 9 will not work.
Luckily, the result of the calculation is always in the range 0<= n >=9, and within that range, sedolchars[n] works.