Is there a way to output the numbers only from a python list?

后端 未结 10 1447
情歌与酒
情歌与酒 2020-12-11 02:15

Simple Question:

list_1 = [ \'asdada\', 1, 123131.131, \'blaa adaraerada\', 0.000001, 34.12451235265, \'stackoverflow is awesome\' ]

I want

10条回答
  •  盖世英雄少女心
    2020-12-11 02:26

    for short of SilentGhost way

    list_2 = [i for i in list_1 if isinstance(i, (int, float))] 
    

    to

    list_2 = [i for i in list_1 if not isinstance(i, str)]
    

提交回复
热议问题