Найти - Пользователи
Полная версия: Помогите решить задачу по определению кол-ва участков в списке
Начало » Python для новичков » Помогите решить задачу по определению кол-ва участков в списке
1 2
Shaman
У Вас где-то ошибочка
  
import random
lst = [random.randint(0, 20) for el in range(40)]
 
def increased_reference(lst):
    result=0
    count=0
    for j in range(len(lst)-2):
        if lst[j+2] > lst[j+1] > lst[j]:
            count+=1
        elif count>=1 and lst[j+1] > lst[j+2]:
            result+=1
            count=0 
    if lst[-1] > lst[-2] > lst[-3]:
        result+=1
    return result
 
def increased(data, frame=2):
    wframe = frame - 1
    count = 0
    current = data[0]
    duration = 0
    for i in data[1:]:
        if i <= current:
            if duration >= wframe:
                count += 1
            duration = 0
        else:
            duration += 1
        current = i
    if duration:
        count += 1
    return count
 
print(lst)
print(increased_reference(lst))
print(increased(lst, 3))
[19, 0, 18, 6, 10, 4, 1, 15, 10, 1, 1, 10, 0, 15, 4, 5, 17, 5, 2, 9, 16, 8, 16, 2, 19, 1, 1, 3, 7, 19, 8, 20, 8, 16, 4, 4, 16, 15, 8, 16]
3
4
>>>
ZerG
вот вопрос
элементы монотонно возрастают (каждое следующее число больше предыдущего).

2 3 4 1
это один участок 2-3-4 или два 2-3, 3-4 ?
FishHook
Какие-то непитоньи решения предлагаете
вот же

    
s = [1, 4, 5, 0, 9, 8, 7, 2, 5, 6, 0]
u = [0]
reduce(lambda x, y: (u.append(1) if y <= x else iadd(u[-1], 1)) or y, s)
print(len(list(filter(None, u))))
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB