Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- # создаем массив псевдослучайных чисел в диапазоне от -100 до 100
- arr = list(map(lambda x: randint(-100, 100), range(0, 29)))
- print(arr) # показываем пользователю элементы массива в терминале
- # ищем наибольшее количество следующих друг за другом отрицательных чисел
- print(len(max(''.join(map(str, list(map(lambda x: int(x < 0), arr)))).replace('0', ' ').split())))
- import itertools
- my_list = [7, 6, -3, -3, -8, 2, -5, 4, -8, -2, -6, -1]
- is_negative = [True if num < 0 else False for num in my_list]
- groups = itertools.groupby(is_negative)
- occurrences_of_negatives = [len(list(g)) for k, g in groups if k]
- result = max(occurrences_of_negatives)
- [False, False, True, True, True, False, True, False, True, True, True, True]`
- {False: [False, False],
- True: [True, True, True],
- False: [False],
- True: [True],
- False: [False],
- True: [True, True, True, True]}
- [3, 1, 4]
Add Comment
Please, Sign In to add comment