I've got some Perl code like this:
my $match = $matches{$key}
? "$matches{$key} was a match!"
: "There was no match."
How is this best rewritten in Python? I'm trying to avoid getting a KeyError.
I've got some Perl code like this:
my $match = $matches{$key}
? "$matches{$key} was a match!"
: "There was no match."
How is this best rewritten in Python? I'm trying to avoid getting a KeyError.
This.
message = "%s was a match"%(matches[key],) if key in matches else "There was no match."