python - Scanning list for 5 consecutive values greater than x -


i want scan large list consecutive values greater x. example x greater 1.0.

for example,

my_list = [0.2, 0.1, 0.3, 1.1, 0.7, 0.5, 1.2, 1.3, 1.4, 1.2, 1.9, 1.1, 0.2, 1.3, 1.5, 1.4, 1.2, 1.1, 0.2, 1.3, 0.1., 1.6, 0.2, 0.5, 1.0, 1.1, 0.2] 

i can subset list by

for in range(0, len(my_list)):     subset = my_list[i:i+5] 

so get

[0.2, 0.1, 0.3, 1.1, 0.7] [0.1, 0.3, 1.1, 0.7, 0.5] [0.3, 1.1, 0.7, 0.5, 1.2] [1.1, 0.7, 0.5, 1.2, 1.3] [0.7, 0.5, 1.2, 1.3, 1.4] [0.5, 1.2, 1.3, 1.4, 1.2] [1.2, 1.3, 1.4, 1.2, 1.9] <-- values want [1.3, 1.4, 1.2, 1.9, 1.1] <-- values want [1.4, 1.2, 1.9, 1.1, 0.2] [1.2, 1.9, 1.1, 0.2, 1.3] [1.9, 1.1, 0.2, 1.3, 1.5] [1.1, 0.2, 1.3, 1.5, 1.4] [0.2, 1.3, 1.5, 1.4, 1.2] [1.3, 1.5, 1.4, 1.2, 1.1] <-- values want 

what best way this?

you can follows:

my_list = [0.2, 0.1, 0.3, 1.1, 0.7, 0.5, 1.2, 1.3, 1.4, 1.2, 1.9, 1.1, 0.2, 1.3, 1.5, 1.4, 1.2, 1.1, 0.2, 1.3, 0.1, 1.6, 0.2, 0.5, 1.0, 1.1, 0.2]  x = 1  result = [my_list[i:i+5] in range(len(my_list)-4) if all(i > x in my_list[i:i+5])] 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -