for-if without list comprehension in one line

后端 未结 5 2039
梦如初夏
梦如初夏 2021-02-15 13:29

can this be written in one line without List Comprehensions?

for x in vec: 
    if x > 3:
         ...
         ...
5条回答
  •  青春惊慌失措
    2021-02-15 13:48

    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)
    

提交回复
热议问题