def previous_key(tuple_of_tuples, key):
 for (i, t) in enumerate(tuple_of_tuples):
  if (t[0] == key):
   try:
    return tuple_of_tuples[(i - 1)][0]
   except IndexError:
    return None

def previous_key ( tuple_of_tuples , key ) : for ( i , t ) in enumerate ( tuple_of_tuples ) : if ( t [ 0 ] == key ) : try : return tuple_of_tuples [ ( i - 1 ) ] [ 0 ] except IndexError : return None
processes a tuple of 2-element tuples and returns the key which comes before the given key .