I am refactoring my code so that it is done in a more pythonic way. Specifically I have a section that is returning tokens from a string if that token is not an integer. Initially I wrote the function as follows
string = "these 5 sentences should not have 2 numbers in them"
newString = []
for token in string.split():
if token.isdigit() == False:
newString.append(token)
newString = " ".join(newString)
print(newString)
While this works I wont to make the code look less clunky. So I rewrote it as follows
newString = [token for token in string.split() if token is not
token.isdigit() ]
But this does not seem to catch the digits. Why is the lambda expression not working ?