Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shops = input().split(' ')
- com_count = int(input())
- def valid_index(i: str, lst: list):
- if len(i) == 1 and i.isdigit():
- return 0 <= int(i) < len(lst)
- for command in range(com_count):
- tokens = input().split(' ')
- cmd = tokens[0]
- if cmd == 'Include':
- shop = tokens[1]
- shops.append(shop)
- elif cmd == 'Visit':
- count = int(tokens[2])
- if count <= len(shops):
- if tokens[1] == 'first':
- shops = [shops[x] for x in range(len(shops)) if x > count - 1]
- elif tokens[1] == 'last':
- shops = [shops[x] for x in range(len(shops) - 1, -1, -1) if x < len(shops) - count][::-1]
- elif cmd == 'Prefer':
- if tokens[1].isdigit() and tokens[2].isdigit():
- if valid_index(tokens[1], shops) and valid_index(tokens[2], shops):
- if int(tokens[1]) != int(tokens[2]):
- idx_1 = int(tokens[1])
- idx_2 = int(tokens[2])
- shops[idx_1], shops[idx_2] = shops[idx_2], shops[idx_1]
- elif cmd == 'Place':
- shop = tokens[1]
- if tokens[2].isdigit():
- idx = str(int(tokens[2]) + 1)
- if valid_index(idx, shops):
- shops.insert(int(idx), shop)
- print(f'Shops left:\n{" ".join(shops)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement