Python:如果项目有数字,则从列表中删除项目

时间:2014-11-28 21:11:19

标签: python

如果我有一个如下所示的列表:

lst = ['unfavorable movements in foreign exchange rates','0 derivative liabilities (b): foreign exchange contracts $ 516 $ 41 $', 'institutions to protect against foreign exchange risks', 'value derivative assets (a): foreign exchange contracts $ 138 $ 12 $'] 如果有一个数字显示,我想从中删除任何项目。换句话说,我希望我的最终列表看起来像:

lst = ['unfavorable movements in foreign exchange rates', 'institutions to protect against foreign exchange risks']

我"杀死"其他项目因为项目包含数字。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

你可以这样试试,

>>> [ item for item in lst if not any(char.isdigit() for char in item) ]
['unfavorable movements in foreign exchange rates', 'institutions to protect against foreign exchange risks']
>>>