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