if i!=0 in list comprehension gives syntax error

后端 未结 3 380
野的像风
野的像风 2021-01-19 04:14

This question is very much like: if/else in Python's list comprehension? and Simple syntax error in Python if else dict comprehension . But still i dont understand what

3条回答
  •  一整个雨季
    2021-01-19 04:57

    Switch the if i!=0 and for i in range(2) parts:

    >>> [i for i in range(2) if i!=0]
    [1]
    >>>
    

提交回复
热议问题