Skip to content

Instantly share code, notes, and snippets.

@luw2007
Created January 31, 2013 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luw2007/4683572 to your computer and use it in GitHub Desktop.
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"] 这样
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