Add tags

Add tags to the following comment

なるほど。その発想を使ってみました。 cycleは与えられたリストを巡回し続ける無限リストで、zipは短い方に会わせて切り詰めます。

これでも算術演算やstrlenは必要ないですね…正規表現を使うよりは黒魔術っぽさがなくていいかも。

>>> cycle(range(3))
<itertools.cycle object at 0x0270AAA8>
>>> zip(_, "hoge")
[(0, 'h'), (1, 'o'), (2, 'g'), (0, 'e')]
1
2
3
4
5
def divid(n, s):
    from itertools import cycle
    xs = zip(cycle(range(n)), s)
    return ["".join(c for i, c in xs if i == j)
             for j in range(n)]

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...