0
How can I make the code return the last letter of each word in a list in python.
Example_list = [ ‘ the ‘ , ‘ cat, ‘ ran ‘ , ‘ across’ , ‘ the ‘ , ‘street’, ‘ to ‘ , ‘catch ‘ , ‘ the ‘ , ‘ mouse’]
2 Answers
+ 1
Make use of indexing, -1 refers to the last characterof the string:
"word"[-1]
+ 1
Example_list = [ ‘ the ‘ , ‘ cat, ‘ ran ‘ , ‘ across’ , ‘ the ‘ , ‘street’, ‘ to ‘ , ‘catch ‘ , ‘ the ‘ , ‘ mouse’]
Last_char_list=[w[-1] for w in Example_list]
print(last_char_list)