Pythonic way to combine FOR loop and IF statement

后端 未结 10 2393
暗喜
暗喜 2020-11-27 09:02

I know how to use both for loops and if statements on separate lines, such as:

>>> a = [2,3,4,5,6,7,8,9,0]
... xyz = [0,12,4,6,242,7,9]
... for x in         


        
10条回答
  •  猫巷女王i
    2020-11-27 10:04

    a = [2,3,4,5,6,7,8,9,0]
    xyz = [0,12,4,6,242,7,9]  
    set(a) & set(xyz)  
    set([0, 9, 4, 6, 7])
    

提交回复
热议问题