jython - Remove all strings from list of strings and integers -


you given: list1 = [2, "berry", "joe", 3, 5, 4, 10, "happy", "sad"]

want return [2, 3, 5, 4, 10]

is possible remove strings list?

using a list-comprehension can construct list elements want.

>>> list1 = [2, "berry", "joe", 3, 5, 4, 10, "happy", "sad"] >>> [i in list1 if isinstance(i, int)] [2, 3, 5, 4, 10] 

alternative in case example have floats , wish keep those, too:

>>> list1 = [2, "berry", "joe", 3, 5, 4, 10.0, "happy", "sad"] >>> [i in list1 if not isinstance(i, str)] [2, 3, 5, 4, 10.0] 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -