def contextwin(l, win):
 assert ((win % 2) == 1)
 assert (win >= 1)
 l = list(l)
 lpadded = ((((win // 2) * [(-1)]) + l) + ((win // 2) * [(-1)]))
 out = [lpadded[i:(i + win)] for i in range(len(l))]
 assert (len(out) == len(l))
 return out

def contextwin ( l , win ) : assert ( ( win % 2 ) == 1 ) assert ( win >= 1 ) l = list ( l ) lpadded = ( ( ( ( win // 2 ) * [ ( - 1 ) ] ) + l ) + ( ( win // 2 ) * [ ( - 1 ) ] ) ) out = [ lpadded [ i : ( i + win ) ] for i in range ( len ( l ) ) ] assert ( len ( out ) == len ( l ) ) return out
win :: int corresponding to the size of the window given a list of indexes composing a sentence l :: array containing the word indexes it will return a list of list of indexes corresponding to context windows surrounding each word in the sentence .