May-26-2019, 06:42 PM
(This post was last modified: May-26-2019, 07:36 PM by python_newbie09.)
thanks a lot for the explanation and the tip to print out the results. will try it as well
I would like to extend this problem to another level where once these sublists are created. I need to iterate through this sublist and extract the index whenever there is a break in sequence. I tried to do that myself but I am not able to come up with a good solution for it. I know it will be easier to create a separate function and to pass the results of this separated arrays to is but beyond that I am not sure how best to proceed. As an example I have the array as below:
array = [0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,3,8,9,10]
and with your help, I achieved the following:
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 3, 8, 9, 10]]
Now I would like to loop into this sublists and when it find a break in the sequence within the sub list it will extract the index and value of it. in this case the break of sequence occurs in the second sublist from 7 to 3. I tried something like below which resulted in TypeError: append() takes exactly one argument (0 given)
The expected output in this case is 3
I would like to extend this problem to another level where once these sublists are created. I need to iterate through this sublist and extract the index whenever there is a break in sequence. I tried to do that myself but I am not able to come up with a good solution for it. I know it will be easier to create a separate function and to pass the results of this separated arrays to is but beyond that I am not sure how best to proceed. As an example I have the array as below:
array = [0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,3,8,9,10]
and with your help, I achieved the following:
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 3, 8, 9, 10]]
Now I would like to loop into this sublists and when it find a break in the sequence within the sub list it will extract the index and value of it. in this case the break of sequence occurs in the second sublist from 7 to 3. I tried something like below which resulted in TypeError: append() takes exactly one argument (0 given)
The expected output in this case is 3
arrays = [[]] # array of sub-arrays for i, num in enumerate(array): arrays[-1].append(num) if num == 10 and i != len(array)-1: arrays.append([]) print(arrays) seq_break = [] for i in arrays: if i[-1] != i[-1] + 1: #checks to see if the next value in the sublist equals to the previous value +1 which means a sequence, if not extract the break value seq_break.append() print(seq_break)