for-if without list comprehension in one line

后端 未结 5 1454
一整个雨季
一整个雨季 2021-02-15 13:09

can this be written in one line without List Comprehensions?

for x in vec: 
    if x > 3:
         ...
         ...
5条回答
  •  灰色年华
    2021-02-15 13:46

    You can imagine somethings like this :

    def do_something(value):
        ...
    
    def do_otherthing(value):
        ...
    
    
    for x in t: do_something(x) if x>3 else do_otherthing(x)
    

提交回复
热议问题