acclivity

pyBoardingList

Nov 10th, 2021 (edited)
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. # Arrange a boarding list for passengers on a plane, starting from the rear (higher row numbers)
  2. # and boarding window seats (A and D) infront of aisle seats (B and C)
  3.  
  4. inlist = ["8A", "2B", "6D", "4C", "1B", "7C", "10B", "6A", "8C", "11A", "9B", "6B"]
  5.  
  6. outlist = []
  7. for s in inlist:
  8.     # Create a value which represents the seat's distance from the aisle
  9.     vs = str(abs(ord(s[-1]) - 66.5))    
  10.     # ord("A") = 65, so 'A' produces 1.5
  11.     # ord('B') = 66, so 'B' produces 0.5
  12.     # ord('C') = 67, so 'C' produces 0.5
  13.     # ord('D') = 68, so 'D' produces 1.5
  14.     # So when sorted in reverse, A and D come before B and C
  15.  
  16.     # Create a list containing seat number (with leading zero if needed) concatenated with aisle distance,
  17.     # Followed by the original seat code as a second entry per tuple
  18.     outlist.append((s[:-1].zfill(2) + vs, s) )  
  19.  
  20. # Sort the resultant list in reverse, and then print the original seat code for each list entry
  21. for tup in sorted(outlist, reverse=True):
  22.     print(tup[1], end="  ")
  23. print()
  24.  
  25. # Output:
  26. # 11A  10B  9B  8A  8C  7C  6D  6A  6B  4C  2B  1B
Advertisement
Add Comment
Please, Sign In to add comment