Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This function returns the first character of the last string in a list
- # It also adds the condition that the list must not be an empty list
- # Otherwise it returns None
- def first_letter_of_last_string(list_of_strings):
- if len(list_of_strings) >= 1: # The length of the list must be greater than 0
- first_of_last = list_of_strings[-1][0]
- return first_of_last
- print(first_letter_of_last_string(["Afeez", "Ishola", "Ganiyu"])) # G
- print(first_letter_of_last_string(["Scholars Network"])) # S
- print(first_letter_of_last_string(["cat", "dog", "zebra"])) # z
- print(first_letter_of_last_string(["nonsense"])) # n
- print(first_letter_of_last_string([])) # None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement