This is my list
JavaScript
x
2
1
lst = [1,2,3,4,4,5,6,7,8,8,9,9,10,1]
2
I want this output
JavaScript
1
2
1
[1][2,3][4,4,5][6,7][8,8,9][9][10,1]
2
If the number is even and the next number is odd loop should break
, and the next odd or even number should be appended in another list.
if there is even number, the list shouldn’t be broken until the next odd is found.
Advertisement
Answer
JavaScript
1
10
10
1
lis = [1,2,3,4,4,5,6,7,8,8,9,9,10,1]
2
tempList = []
3
result = []
4
for item in lis:
5
tempList.append(item)
6
if item % 2 == 1:
7
result.append(tempList)
8
tempList = []
9
print(result)
10