0

I am trying to find subset of consequent numbers in a list(consisting of interger)type data by using python code. but, it was not easy for me. So, I came here for advice.

Here is example. It is a part of my list. (It is kind of a observation number.)

A = [8,9,10,11,25,26,27,28,42,43,44,45,46,47,78,79,80,81,82,83,84,85,86,251,252,253,254]

And i am trying to do:

Make a list of consecutive number sets. If there are 5 consecutive number sets, 5 list should be generated and the number of list should be A1, A2, A3, A4, A5 like below.

A1 = [8,9,10,11]
A2 = [25,26,27,28]
A3 = [42,43,44,45,46,47,48]
A4 = [78,79,80,81,82,83,84,85,86]
A5 = [251,252,253,254]

How can i do this with python code(by only using built-in function)

the characteristics of this list A is:

  1. the order of numbers is always ascending.
  2. there is no regularity like sequence. it is just a result of removing some numbers which has a problem in observing result.

please help me..

DYZ
  • 55,249
  • 10
  • 64
  • 93
yj lee
  • 1
  • https://www.geeksforgeeks.org/python-find-groups-of-strictly-increasing-numbers-in-a-list/ – chrisHG Jul 26 '20 at 04:53
  • Does this helps: https://stackoverflow.com/questions/58432920/make-list-as-nested-list-with-consecutive-elements-in-separate-list? – Pygirl Jul 26 '20 at 04:56

0 Answers0