How python slides the value window with compressors and iterators in the list
This article is about how python slides through the value window with compressors and iterators in the list. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Slide the value window with compressors and iterators in the list
Def n_grams (a, n):... Z = [iter (a [I:]) for i in range (n)]. Return zip (* z)... > > a = [1,2,3,4,5,6] > > n_grams (a, 3) [(1,2,3), (2,3,4), (3,4,5), (4,5,6)] > > n_grams (a, 2) [(1,2), (2,3), (3,4), (4,5)] > > n_grams (a, 4) [(1,2,3) 4), (2, 3, 4, 5), (3, 4, 5, 6)] Thank you for reading! This is the end of the article on "how python slides the value window with compressors and iterators in the list". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!