def trim_center_of_string(string,max_size): ''' String: hellogoodbye max_size: 8 return hellbyes ''' if len(string) >= max_size: # lets trim the center our long string length = len(string) excess = len(string) - max_size left_imit = (length/2)-(excess/2) # hell|os&goodbyes right_limit = left_imit+excess # hellos&good|byes left_part = string[:left_imit] # hell| right_part = string[right_limit:-1]# |byes string = left_part+right_part # hellbyes return string