greentea #4264(2007/11/19 16:56 GMT) [ Python ] Rating1/1=1.00
文字数数えるのが面倒だったので、スライスでn個飛ばしの文字列を作って、それの文字数を使いました。 オフセット数えるのも、面倒なので再帰任せです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# encoding: utf-8 sample = u"ゆめよりもはかなき世のなかをなげきわびつゝあかしくらすほどに四月十よひにもなりぬれば木のしたくらがりもてゆく" def divid(str, n, target_list=[]): def get_splitted_str(str, n): return str[:len(str[::n])] if str: s = get_splitted_str(str, n) return divid(str[len(s):], n-1, target_list+[s]) else: return target_list for i in range(4,7): print "divid", i l = divid(sample, i) for line in l: print line print ""
Rating1/1=1.00-0+
[ reply ]
greentea #4264() [ Python ] Rating1/1=1.00
Rating1/1=1.00-0+
[ reply ]