ngram.py
def Ngram( N , lst ):
returnLst = []
for i in range( len( lst ) - N + 1 ):
returnLst.append( lst[ i : i + N ] )
return returnLst
lst = ['0', '1', '2', '3', '4', '5']
print(Ngram( 4, lst ))
#[['0', '1', '2', '3'], ['1', '2', '3', '4'], ['2', '3', '4', '5']]
Recommended Posts