Iterate over slices of a string

Posted tnyleyon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Iterate over slices of a string相关的知识,希望对你有一定的参考价值。

def iter_slices(string, slice_length):
"""Iterate over slices of a string."""
pos = 0
if slice_length is None or slice_length <= 0:
slice_length = len(string)
while pos < len(string):
yield string[pos:pos + slice_length]
pos += slice_length

s = "thisisatest"
o = 2
p = iter_slices(s,o)
print p
print (p.next())
print (p.next())
print (p.next())
print (p.next())















以上是关于Iterate over slices of a string的主要内容,如果未能解决你的问题,请参考以下文章

[ES2017] Iterate over properties of an object with ES2017 Object.entries()

How to Iterate Over a Map in Java?

python 来自http://stackoverflow.com/questions/12325608/iterate-over-a-dict-or-list-in-python/12325691#

How do I iterate over a Scala List (or more generally, a sequence) using theforeach method or for lo

[Python Debug] SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a Data

无法从 Handlebars 中的数组访问对象属性