Structural Pattern Matching
Completed
Read commands and handle them with match on the split list: go DIRECTION, pick ITEM [ITEM...], quit, anything else. Print moving DIRECTION, picked N items: ..., bye or ?.
Input
Line 1: n. Then n commands.
Output
n lines.
Example
Input
5 go north pick key lamp pick quit dance now
Output
moving north picked 2 items: key, lamp ? bye ?
Editor
Python
Hints
case ["go", direction] matches a 2-item list starting with go.
*items captures the rest; add if items as a guard.
Solution explanation
Pattern matching can destructure sequences and add guards — far clearer than nested ifs on lengths and indexes.
Show solution
for _ in range(int(input())):
match input().split():
case ["go", direction]:
print(f"moving {direction}")
case ["pick", *items] if items:
print(f"picked {len(items)} items: {', '.join(items)}")
case ["quit"]:
print("bye")
case _:
print("?")