python 3 select just the integer from a list with strings -
I have a problem related to Python 3:
I get a list containing I just want to get the integer by bus Edit : Yes, you are right; It breaks down with negative values in stars, and there will be a more long approach: [integer One variable (sometimes 1, sometimes 5, sometimes 938, etc.).
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]
& gt; & Gt; & Gt; N = []> & Gt; & Gt; For L: ... Try: ... n.append (int (elem)) ... except ValueError: ... pass ... & gt; & Gt; & Gt; N [1, 2]
Comments
Post a Comment