Like in this question, I am trying to match an element in a list, and handle the cases accordingly. See the example below.
direct_payments = ["creditcard", "debitcard"]
on_credits = ["gift card", "rewards program"]
def print_payment_type(payment_type):
match payment_type:
case in direct_payments:
print("You paid directly!")
case in on_credits:
print("You paid on credits!")
print_payment_type("gift card")
I want this to print "You paid on credits"
. I am convinced that using structural pattern matching is the most readable option in my case. Is there any way to achieve this behaviour? I cannot use "gift card" | "rewards program"
, because I need to use the lists elsewhere.