How to remove words in a string that start with specific character in Python

2 Answers

0 votes
s = "java python c c++ php c# rust go pascal"

words = " ".join(word for word in s.split() if not word.startswith("p"))

print(words)




'''
run:

java c c++ c# rust go

'''

 



answered Nov 26, 2022 by avibootz
0 votes
s = "java python c c++ php c# rust go pascal"

words = " ".join(filter(lambda word: not word.startswith("p"), s.split()))

print(words)




'''
run:

java c c++ c# rust go

'''

 



answered Nov 26, 2022 by avibootz
...