Skip to content

Tag: list

Compute cummulative sum until a zero appears

I have a (long) list in which zeros and ones appear at random: list1 = [1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1] 1.I want to get another list the sum of the list up to where 0 appears where 0 appears, retain 0 in the list list2 = [3, 0, 2, 0, 1, 0, 3]

Occurence of a value in many lists

i have a Series Object in pandas with 2 columns, one for the indices and one with lists, I need to find if a value occurs in only one of these lists and return it with the most optimal way. As an example let’s say we have this i need to return 77 because it occurs in only one of