Get the App
SLTechnology News&Howtos  ›  Development  › 

How python slides the value window with compressors and iterators in the list

Shulou Source: shulou.com Published: 2022-06-01 05:43:05 09月30日 Update

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!

Tags: Use Compressor iteration content more articles good practical articles read knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Microsoft Shulou Information macOS