List comprehension replacing items that are not float or int

后端 未结 5 604
一个人的身影
一个人的身影 2021-01-17 02:21

I have a 2 item list.

Sample inputs:

[\'19(1,B7)\', \'20(1,B8)\']
[\'16 Hyp\', \'16 Hyp\']
[\'< 3.2\', \'38.3302615548213\']
[\'18.6086945477694\         


        
5条回答
  •  一个人的身影
    2021-01-17 02:31

    What about

    def stip_chars(lst):
        for item in lst:
            yield item.strip("> ")
    
    new_values = [v for v in strip_chars(values) if is_number(v)]
    

    ?

提交回复
热议问题