Guest User

Untitled

a guest
Jan 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. [7, 100, 83, 1000, 9, 100, 19]
  2.  
  3. [700, 83, 1000, 900, 19]
  4.  
  5. stack2 = []
  6. i = 1
  7. while i < len(stack):
  8. if stack[i] == 100:
  9. stack2.append(stack[i-1]*100)
  10. elif len(stack) == 2 and i == len(stack)-1: # Гдето здесь ошибка есть
  11. stack2.append(stack[i-1])
  12. stack2.append(stack[i])
  13. elif i == len(stack)-1:
  14. stack2.append(stack[i])
  15. elif stack[i-1] != 100:
  16. stack2.append(stack[i-1])
  17. i += 1
  18.  
  19. lst = [7, 100, 83, 1000, 9, 100, 19]
  20. lst2 = []
  21. for i in range(len(lst)):
  22. if i != len(lst) - 1:
  23. if lst[i+1] == 100:
  24. lst2.append(lst[i] * 100)
  25. else:
  26. lst2.append(lst[i])
  27. lst2.append(lst[-1])
  28. print(lst2)
  29.  
  30. from functools import reduce
  31.  
  32. data = [7, 100, 83, 1000, 9, 100, 19]
  33.  
  34. reduce(lambda acc, val: acc[:-1] + [acc[-1] * val] if val == 100 and len(acc) else acc + [val], data, [])
  35.  
  36. x = [7, 100, 83, 1000, 9, 100, 19]
  37.  
  38. for value, index in zip(reversed(x[1:]), range(len(x) - 1, 0, -1)):
  39. if (value == 100):
  40. x[index - 1] *= x.pop(index)
  41.  
  42. print(x) # [700, 83, 1000, 900, 19]
Add Comment
Please, Sign In to add comment