Advertisement
go6odn28

group_of_tens

Feb 16th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # no dictionary
  2. numbers_sequence = list(map(int, input().split(", ")))
  3. max_group = max(numbers_sequence) // 10 + 1
  4. if max(numbers_sequence) % 10 == 0:
  5.     max_group -= 1
  6. current_group = 0
  7. for groups in range(max_group):
  8.     group_list = [number for number in numbers_sequence if current_group < number <= (current_group + 10)]
  9.     current_group += 10
  10.     print(f"Group of {current_group}'s: {group_list}")
  11.     group_list.clear()
  12.  
  13.  
  14.  
  15. #with_dictionary
  16. list_numbers = [int(x) for x in input().split(", ")]
  17. sorted_groups = {}
  18. group = 0
  19.  
  20. while True:
  21.     if not list_numbers:
  22.         break
  23.  
  24.     if max(list_numbers) > group:
  25.         group += 10
  26.  
  27.     sorted_groups[group] = [num for num in list_numbers if num <= group]
  28.     list_numbers = [x for x in list_numbers if x > group]
  29.  
  30. for key, value in sorted_groups.items():
  31.     print(f"Group of {key}'s: {value}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement