python 3 select just the integer from a list with strings -


I have a problem related to Python 3:

I get a list containing [integer One variable (sometimes 1, sometimes 5, sometimes 938, etc.).

I just want to get the integer by bus

  and  & gt; ; & Gt; L = [b'1 ', b'2', b'abc ']> gt; & Gt; & Gt; N = [Ele (Elem) for elem if elem.isdigit ()]> gt; & Gt; & Gt; Print N [1, 2]  

Edit : Yes, you are right; It breaks down with negative values ​​in stars, and there will be a more long approach:

  & gt; & Gt; & Gt; N = []> & Gt; & Gt; For L: ... Try: ... n.append (int (elem)) ... except ValueError: ... pass ... & gt; & Gt; & Gt; N [1, 2]  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -