def classify_saves(saves, period_start):
 def retain_oldest_in_region(region):
  prev = None
  for save in region:
   if prev:
    (yield (False, prev))
   prev = save
  if prev:
   (yield (True, prev))
 (matches, rest) = partition((lambda s: (s[0] >= period_start['all'])), saves)
 for save in matches:
  (yield (True, save))
 tm_ranges = ((period_start['dailies'], (lambda s: localtime(s[0]).tm_yday)), (period_start['monthlies'], (lambda s: localtime(s[0]).tm_mon)), (period_start['yearlies'], (lambda s: localtime(s[0]).tm_year)))
 for (pstart, time_region_id) in tm_ranges:
  (matches, rest) = partition((lambda s: (s[0] >= pstart)), rest)
  for (region_id, region_saves) in groupby(matches, time_region_id):
   for action in retain_oldest_in_region(region_saves):
    (yield action)
 for save in rest:
  (yield (False, save))

def classify_saves ( saves , period_start ) : def retain_oldest_in_region ( region ) : prev = None for save in region : if prev : ( yield ( False , prev ) ) prev = save if prev : ( yield ( True , prev ) ) ( matches , rest ) = partition ( ( lambda s : ( s [ 0 ] >= period_start [ 'all' ] ) ) , saves ) for save in matches : ( yield ( True , save ) ) tm_ranges = ( ( period_start [ 'dailies' ] , ( lambda s : localtime ( s [ 0 ] ) . tm_yday ) ) , ( period_start [ 'monthlies' ] , ( lambda s : localtime ( s [ 0 ] ) . tm_mon ) ) , ( period_start [ 'yearlies' ] , ( lambda s : localtime ( s [ 0 ] ) . tm_year ) ) ) for ( pstart , time_region_id ) in tm_ranges : ( matches , rest ) = partition ( ( lambda s : ( s [ 0 ] >= pstart ) ) , rest ) for ( region_id , region_saves ) in groupby ( matches , time_region_id ) : for action in retain_oldest_in_region ( region_saves ) : ( yield action ) for save in rest : ( yield ( False , save ) )
for each in saves .