-2

I have a python list ['100', '20.0', '?', 'a', '0']. The list contains real strings '?', 'a' and ints and floats coded in strings. I am trying to find the (real) strings '?', 'a' in the list.

locke14
  • 1,335
  • 3
  • 15
  • 36
kosa
  • 262
  • 4
  • 17

1 Answers1

2
data = ['100', '20.0', '?', 'a', '0']

result = []
for item in data:
    if not any(c.isnumeric() for c in item): # check if number exist in string
        result.append(item)
print (result)

output:

['?', 'a']

what is equal to list comprehension:

print ([item for item in data if not any(c.isnumeric() for c in item) ])

output:

['?', 'a']
ncica
  • 7,015
  • 1
  • 15
  • 37