Created
January 31, 2013 15:17
-
-
Save luw2007/4683572 to your computer and use it in GitHub Desktop.
比如我有一个列表(字符串) l1 = "abcdef",然后有对应的另一个列表l2 = [1, 2, 1, 1, 2, 2]
两个列表是对应的,现在我要更加列表l2的叠加值分段返回l1,如果设定l2列表叠加的值>=3为一段
返回 ["ab", "cde", "f"] 这样
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_(l1, l2): | |
out = [] | |
w = i = 0 | |
for j, item in enumerate(l2, 1): | |
w += item | |
if w >= 3: | |
out.append(l1[i:j]) | |
w, i = 0, j | |
if i != j: | |
out.append(l1[i:]) | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment