def pad_sequence(sequence, n, pad_left=False, pad_right=False, left_pad_symbol=None, right_pad_symbol=None):
 sequence = iter(sequence)
 if pad_left:
  sequence = chain(((left_pad_symbol,) * (n - 1)), sequence)
 if pad_right:
  sequence = chain(sequence, ((right_pad_symbol,) * (n - 1)))
 return sequence

def pad_sequence ( sequence , n , pad_left = False , pad_right = False , left_pad_symbol = None , right_pad_symbol = None ) : sequence = iter ( sequence ) if pad_left : sequence = chain ( ( ( left_pad_symbol , ) * ( n - 1 ) ) , sequence ) if pad_right : sequence = chain ( sequence , ( ( right_pad_symbol , ) * ( n - 1 ) ) ) return sequence
returns a padded sequence of items before ngram extraction .