White scenery @showyou, hatena

If you have any comments, you may also send twitter @shsub or @showyou.

特定の要素で単語を分割

こんなのあったっけ?

def splitList(list,split):
	retListArray = []
	tmpList=[]
	for x in list:
		tmpList.append(x)
		if x == split:
			retListArray.append(tmpList)
			tmpList = []
	retListArray.append(tmpList)
	return retListArray

if __name__ == "__main__":
	inList = [ "a", "b", "c", "a", "b", "c", "b", "c" ]
	listArray = splitList(inList,"c");
	print listArray

結果:

[['a', 'b', 'c'], ['a', 'b', 'c'], ['b', 'c'], []]