I want to do an assignment which defaults to another if it fails.
this = {'one':1}
test = this['a'] if this['a'] else "Wololo"
I get a KeyError when I try this. Reason I need a one liner assignment is I have a minimum of five characters which may be in the dictionary and that requires five separate try blocks to check without returning an error.
defaultdict..getis the real answer, but note that the ternary version would work if you made itthis['a'] if 'a' in this else ...