我试图检查sent1或sent2的长度是否为零,如果有,我想将sent_witn_not_null
设置为具有非零列表的列表。但我写的if-else条件似乎很复杂。什么是更简单的方法?在
sent1 = ["this","is","foo","bar"]
sent2 = []
if len(sent1) or len(sent2) == 0:
sent_with_not_null = sent2 if len(sent1) == 0 else sent1
sent_with_not_null = sent1 if len(sent2) == 0 else sent2
利用Python的合并运算符。在
像这样?在
或者:
^{pr2}$相关问题 更多 >
编程相关推荐