my_list = ["a3", "b3", "aa"]
def erase(lista):
only_chars = []
for word in lista:
result = ''.join([w for w in word if not w.isdigit()])
if result:
only_chars.append(result)
return only_chars
result = erase(my_list)
print(result)
它将打印:
['a', 'b', 'aa']
数字
结合
any
:
my_list = ["a3", "b3", "aa"]
def erase(lista):
only_chars = []
for word in lista:
if not any(w.isdigit() for w in word):
only_chars.append(word)
return only_chars
result = erase(my_list)
print(result)