æ¸ãã¦ã¿ã
ã追è¨ãend å¼æ°ã使ãã®ãå¿ãã¦ãã®ã§, ã¡ãã£ã¨ä¿®æ£
@atsuoishimoto ããã«ã¯è² ãã¾ãã.
#!/usr/bin/env python # -*- coding: utf-8 -*- def limit_characters1(s, start, maximum, end=None): """ >>> for i in limit_characters1("12345", 0, 2): ... print(i) 12 34 5 >>> for i in limit_characters1("123456789", 1, 3): ... print(i) 234 567 89 >>> for i in limit_characters1("123456789", 2, 3): ... print(i) 345 678 9 >>> for i in limit_characters1("123456789", 3, 3): ... print(i) 456 789 """ return (s[start + i * maximum:min((end or len(s)), start + (i + 1) * maximum)] \ for i in range(((end or len(s)) - start - 1) / maximum + 1)) def _test(): import doctest doctest.testmod() if __name__ == '__main__': _test()