my_list = [(1, "a"),(2, "b"), (1, "e"), (3, "b"), (2, "c"), (1, "b"), (0, "b")]result, temp = [], []for item in my_list: temp.append(item) if item[1] == 'b': result.append(temp) temp = []if len(temp) > 0: result.append(temp)print result# [[(1, 'a'), (2, 'b')], [(1, 'e'), (3, 'b')], [(2, 'c'), (1, 'b')], [(0, 'b')]]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)