python: extract integers from mixed list

前端 未结 4 832
无人及你
无人及你 2020-12-22 12:02

(python 2.7.8)

I\'m trying to make a function to extract integers from a mixed list. Mixed list can be anything but the e.g. I\'m going with is:

test         


        
4条回答
  •  既然无缘
    2020-12-22 12:49

    testList = [1, 4.66, 7, "abc", 5, True, 3.2, False, "Hello", 7]
    print([x for x in testList if isinstance(x,int) and not isinstance(x,bool)])
    [1, 7, 5, 7]
    

提交回复
热议问题