Examples :
Input: [1, 2, 3, 5, 6] Output: [[ 1, 2, 3], [5, 6]] Input: [8, 9, 10, 7, 8, 1, 2, 3] Output: [[ 8, 9, 10], [7, 8], [1, 2, 3]]
Approach # 1: Python is naive
It’s naive an approach that takes advantage of the extra space of the input list. It uses a for loop and at each iteration checks if the next item is incremented from the previous one by 1. If yes, add it to the current sublist, otherwise create another sublist.
# Python3 group finder
The number of strictly increasing numbers within
def
groupSequence (lst):
res
=
[[lst [
0
]]]
for
i
in
range
(
1
,
len
(lst)):
if
lst [i

1
]
+
1
=
=
lst [i]:
res [

1
]. append (lst [i])
else
:
res.append ([lst [i]])
return res
# Driver program
l
=
[
8
,
9
,
10
,
7
,
8
,
1
,
2
,
3
]
print
(groupSequence (l ))
Exit:
[ [8, 9, 10], [7, 8], [1, 2, 3]]
Approach # 2: Alternative naive
This alternative to above a very naive approach. This method is pretty straightforward and straightforward. It creates a start list and a end list that contains the position of the starting and ending sequence of increasing integers. So, just revert the borders using for loops.

Exit:
[[8, 9, 10 ], [7, 8], [1, 2, 3]]
Approach # 3. Using iterable and profitable
This approach uses a different list & # 39 ; res & # 39; and repeatable & # 39; it & # 39 ;. Variable & # 39; prev & # 39; is used to store a record of the previous integer, and start is used to get the starting position of the ascending sequence. Using a loop, in each iteration, we check if the initial element is a successor to prev or not. If yes, we add it to res, otherwise we just issue res + [prev] as a list item.

Exit:
[[8, 9, 10], [7, 8], [1, 2, 3 ]]
Approach # 4 Using itertools
Python’s itertools provides operations such as looping and group invocation that are used in this method. First, we form another list & # 39; temp_list & # 39; using a loop. The loop generates an infinitely repeating series of values. Then we group temp_list accordingly with the groupby operation and finally get the desired result.

Exit:
[(8, 9, 10), (7, 8), (1, 2, 3 )]