daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Aug 17th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from random import randint
  2.  
  3. # создаем массив псевдослучайных чисел в диапазоне от -100 до 100
  4. arr = list(map(lambda x: randint(-100, 100), range(0, 29)))
  5. print(arr) # показываем пользователю элементы массива в терминале
  6. # ищем наибольшее количество следующих друг за другом отрицательных чисел
  7. print(len(max(''.join(map(str, list(map(lambda x: int(x < 0), arr)))).replace('0', ' ').split())))
  8.    
  9. import itertools
  10.  
  11. my_list = [7, 6, -3, -3, -8, 2, -5, 4, -8, -2, -6, -1]
  12.  
  13. is_negative = [True if num < 0 else False for num in my_list]
  14. groups = itertools.groupby(is_negative)
  15. occurrences_of_negatives = [len(list(g)) for k, g in groups if k]
  16.  
  17. result = max(occurrences_of_negatives)
  18.    
  19. [False, False, True, True, True, False, True, False, True, True, True, True]`
  20.    
  21. {False: [False, False],
  22.  True:  [True, True, True],
  23.  False: [False],
  24.  True:  [True],
  25.  False: [False],
  26.  True:  [True, True, True, True]}
  27.    
  28. [3, 1, 4]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top