Advertisement
Davitkova

02. Destinations Mapper using filter

Jun 17th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. destinations = input()
  2.  
  3.  
  4. def extract_destinations():
  5.  
  6.     return destinations.split('=') + destinations.split('/')
  7.  
  8.  
  9. def validate_destinations(destination):
  10.  
  11.     return str(destination[:]).isalpha() \
  12.                 and str(destination[0]) == str(destination[0]).upper() \
  13.                 and len(destination) >= 3
  14.  
  15.  
  16. def calculate_travel_points():
  17.  
  18.     points = 0
  19.     for destination in valid_destinations:
  20.         points += len(destination)
  21.  
  22.     return points
  23.  
  24.  
  25. extracted_destinations = extract_destinations()
  26. valid_destinations = list(filter(validate_destinations, extracted_destinations))
  27. travel_points = calculate_travel_points()
  28.  
  29. print(f"Destinations: {', '.join(valid_destinations)}")
  30. print(f"Travel Points: {travel_points}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement