Category Archives: python

Python posts

How to determine the performance hit of regular expressions

This coding example is really about how to figure out what is faster. In some cases regular expressions may be the optimal solution but as a rule of thumb they are suboptimal for the simpler cases. e.g. starts with, ends … Continue reading

Posted in programming, python | Leave a comment

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