I have a list e.g. ["1","2","n","5","n","x","0","v","-","a","l","4","1","v","m","z","o","5","%","d",";","a","m","6"]
I want to print out the elements that are a letter or special symbol.
how do I do this?
CodePudding user response:
You can use isdigit()
. Like so:
some_str = "12a"
for i in some_str:
print(i.isdigit())
# outputs
True
True
False
CodePudding user response:
Python comes with an isnumeric()
method that returns true when a string is a number. In the case you listed you could try:
string_list = ["1","2","n","5","n","x","0","v","-","a","l","4","1","v","m","z","o","5","%","d",";","a","m","6"]
for value in string_list:
if not value.isnumeric():
print(value)
...which would output
n
n
x
v
-
a
l
v
m
z
o
%
d
;
a
m