I have a list : list_data = [1,2,3,4,5,6,7,8]
.
I want to find nested lists that will group continuous value if it has the number of standard deviations <= a specific number.
Expect results (a specific number is 2
): list_data = [[1,2,3,4,5,6],[7,8]]
.
Can I do that with list comprehension?
I have tried:
import statistics
list_data = [1,2,3,4,5,6,7,8]
results = [list(g) for key,[*g] in groupby(list1) if statistics.stdev(list(g)) <=2]
But maybe groupby
can group the same value in the list so it's not working.
My question is can I do that with Python List comprehension
or another solution with the best performance?