def tuple_key(tup):
 def generator():
  for item in tup:
   try:
    (yield (1, int(item)))
   except ValueError:
    (yield (0, item))
 return tuple(generator())

def tuple_key ( tup ) : def generator ( ) : for item in tup : try : ( yield ( 1 , int ( item ) ) ) except ValueError : ( yield ( 0 , item ) ) return tuple ( generator ( ) )
return a sort key for mixed int/string tuples .