webbersof

Untitled

Oct 12th, 2022
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. # 1. No Vowels
  2.  
  3. text = input()
  4. vowels = ['a', 'o', 'u', 'e', 'i']
  5. result = ''
  6. for ch in text:
  7. if ch.lower() not in vowels:
  8. result += ch
  9.  
  10. print(result)
  11.  
  12. # 2. Trains
  13. number = int(input())
  14. wagons = [0] * number
  15. command = input()
  16.  
  17. while True:
  18. command = input()
  19.  
  20. if command == 'End':
  21. break
  22.  
  23. split_command = command.split(' ') # insert 0 15
  24. current_command = split_command[0]
  25.  
  26. if current_command == 'add':
  27. people_to_add = int(split_command[1])
  28. wagons[-1] += people_to_add
  29.  
  30. elif current_command == 'insert':
  31. index = int(split_command[1]) # insert 0 15
  32. number_of_people = int(split_command[2])
  33. wagons[index] += number_of_people
  34.  
  35. elif current_command == 'leave':
  36. index = int(split_command[1])
  37. people_to_leave = int(split_command[2])
  38. wagons[index] -= people_to_leave
  39.  
  40. print(wagons)
  41.  
  42. # 3. To-do List
  43. tasks = []
  44.  
  45. while True:
  46. command = input()
  47.  
  48. if command == 'End':
  49. break
  50.  
  51. split_command = command.split('-')
  52. priority = int(split_command[0])
  53. current_task = split_command[1]
  54.  
  55. tasks.append([priority, current_task])
  56.  
  57. sorted_tasks = []
  58. for task_data in sorted(tasks):
  59. sorted_tasks.append(task_data[1])
  60.  
  61. print(sorted_tasks)
  62.  
  63. # 4. Palindrome Strings
  64. def palindrome_filtered(word):
  65. if word == word[::-1]:
  66. return word
  67.  
  68. words = input().split(' ')
  69. palindrome = input()
  70.  
  71. palindrome_list = [word for word in words if palindrome_filtered(word)]
  72. palindrome_counter = palindrome_list.count(palindrome)
  73.  
  74. print(palindrome_list)
  75. print(f'Found palindrome {palindrome_counter} times')
  76.  
  77. # 5. Sorting Names
  78. names = input().split(', ')
  79. result = sorted(names, key=lambda item: (-len(item), item))
  80. print(result)
  81.  
  82. # 6. Even Numbers
  83. numbers = list(map(int, input().split(', ')))
  84. indices = [num for num in range(len(numbers)) if numbers[num] % 2 == 0]
  85. print(indices)
  86.  
  87.  
  88. # speed timeit
  89. import timeit
  90.  
  91. a = timeit.timeit(stmt='''lst = []
  92. for n in range(10000):
  93. lst.append(n)''', number=10000)
  94.  
  95. b = timeit.timeit(stmt='lst = [n for n in range(10000)]', number=10000)
  96.  
  97. print(a)
  98. print(b)
  99.  
Advertisement
Add Comment
Please, Sign In to add comment