I have a list that looks like this -
nums = [0,0,0,0,1,1,2,3,4,5,6,0,0,0,0,1,2,3,4,5,6,0,0,0,0]
I want to get the numbers between the 0s in the list. For this, I used the code below -
groups = list(itertools.groupby(nums, lambda item:item != 0))
groups = list(filter(lambda item:item[0], groups))
list(map(lambda item:list(item[-1]), groups))
But I am getting empty lists as the output -
[[], []]
My desired output is -
[[1,1,2,3,4,5,6], [1,2,3,4,5,6]]
How can I do this using itertools.groupby
?