def complete_year_spans(spans):
 spans.sort(key=(lambda x: x['from']))
 for (x, y) in pairwise(spans):
  if ('to' not in x):
   x['to'] = (y['from'] - 1)
 if (spans and ('to' not in spans[(-1)])):
  spans[(-1)]['to'] = datetime.now().year

def complete_year_spans ( spans ) : spans . sort ( key = ( lambda x : x [ 'from' ] ) ) for ( x , y ) in pairwise ( spans ) : if ( 'to' not in x ) : x [ 'to' ] = ( y [ 'from' ] - 1 ) if ( spans and ( 'to' not in spans [ ( - 1 ) ] ) ) : spans [ ( - 1 ) ] [ 'to' ] = datetime . now ( ) . year
set the to value of spans if empty and sort them chronologically .