-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,217
  • 3
  • 14
  • 32
kosa
  • 247
  • 2
  • 16

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
  • 6,737
  • 1
  • 14
  • 33