【发布时间】:2022-12-27 21:41:39
【问题描述】:
How to I check if a value exist and then return it and if it doesnt, return an empty dict {} (or any other operation) in one line?
I currently do the following which I feel could be done in a much morepythonway:
if (test[0].value):
value = test[0].value
else
value = {}
【问题讨论】:
-
What do you mean with "exist"? Your current code has no existence check.
标签: python