2014-11-28 5 views
-3

이있는 경우 목록에서 항목을 제거 :파이썬 :이처럼 보이는 목록이있는 경우 항목은 숫자

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

당신은 몇 가지 코드를 작성하여이 작업을 수행 할 수 있습니다. –

답변

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'] 
>>> 
+1

나보다 7 초 빠름 :-) –

+0

:) @FrerichRaabe –

+0

'char.isdigit()'에 대해 몰랐습니다. 감사합니다 – Plug4

관련 문제