How can I filter items from a list in Python?

前端 未结 2 648
野趣味
野趣味 2020-12-16 16:42

I have data naively collected from package dependency lists.

Depends: foo bar baz >= 5.2

I end up with

 d = set([\'foo\',\'bar\',\'baz\',\'         


        
2条回答
  •  没有蜡笔的小新
    2020-12-16 17:44

    How about

    d = set([item for item in d if re.match("^[a-zA-Z]+$",item)])
    

    that gives you just the values you want, back in d (the order may be different, but that's the price you pay for using sets.

提交回复
热议问题