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())
原文地址:https://www.cnblogs.com/tnyleyon/p/9452844.html
时间: 2024-11-10 13:10:10