if-else in a dictionary comprehension [duplicate]
问题 This question already has answers here : Ternary expression in dictionary comprehension (2 answers) Closed 3 years ago . Is it possible to use the else statement (and if yes, how?) in a dictcomp ? It is not possible to use else as part of the comprehension itself (see this) but at least in list and set comprehensions it is possible to use the conditional_expression (see this). An example for listcomp is here. My example code is: converters = {"id": int} rows = [{"id": "1", "name": "foo"}, {