Tag Archives: postaday2011

Smarter last name first function

def last_first(name):   “””   Return last_name, first_name.   Checks for already reversed names.   Looks for some suffixes after the last name.   Only works with one part last names.   Leaves names like ‘Charles III’ as is.   “””   SUFFIXES = (‘jr’, ‘jnr’, ‘sr’, ‘snr’, … Continue reading

Posted in python | Tagged , , , | 1 Comment

Naive last name first function

def last_first(name):   “””   Return last_name, first_name.   Checks for already reversed names.   Assumes no suffix and one part last names.   “””   retval = name   if name and ‘,’ not in name:     parts = name.split()     retval = parts[-1] + ‘, ‘ + … Continue reading

Posted in python | Tagged , , , | Leave a comment

The digits of a number in reverse as a generator

def digits(n):   q, m = divmod(n, 10)   while q or m:     yield m     q, m = divmod(q, 10)

Posted in python | Tagged , , , | 1 Comment