标签:this ext none while next += ring string slice
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
标签:this ext none while next += ring string slice
原文地址:https://www.cnblogs.com/tnyleyon/p/9452844.html