Reputation: 31
I want to find the first occurrence of a specific letter and then print out the word where the character first appears. The letter can be upper or lower case.
Upvotes: 0
Views: 51
Reputation: 51
You can use split() method:
def fun(string, char):
for word in string.split():
if char in word:
return word
return None
print(fun('abc def ghjk ldsa l', 'e'))
Above code will result in:
def
Upvotes: 1