Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

334
Views
Python match/case using dictionary keys and values

I'm making a pygame game, and whenever I run my code I get the error expected ':'. I am aware that using [ and ] in match/case blocks is used for something else, but how do I get around this issue?

case pygame.KEYDOWN:

    match event.key:

        case game.controls["pan_up"]:
            world_pos[1] -= 1

        case game.controls["pan_left"]:
            world_pos[0] -= 1

        case game.controls["pan_down"]:
            world_pos[1] += 1

        case game.controls["pan_right"]:
            world_pos[0] += 1

Error message box

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use .get

example based on your code:

case pygame.KEYDOWN:

    match event.key:

        case game.controls.get("pan_up"):
            world_pos[1] -= 1

        case game.controls.get("pan_left"):
            world_pos[0] -= 1

        case game.controls.get("pan_down"):
            world_pos[1] += 1

        case game.controls.get("pan_right"):
            world_pos[0] += 1
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!