Advertisement
ganiyuisholaafeez

First Character of the Last String

Feb 22nd, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. # This function returns the first character of the last string in a list
  2. # It also adds the condition that the list must not be an empty list
  3. # Otherwise it returns None
  4.  
  5. def first_letter_of_last_string(list_of_strings):
  6.     if len(list_of_strings) >= 1: # The length of the list must be greater than 0
  7.         first_of_last = list_of_strings[-1][0]
  8.         return first_of_last
  9.  
  10. print(first_letter_of_last_string(["Afeez", "Ishola", "Ganiyu"])) # G  
  11. print(first_letter_of_last_string(["Scholars Network"])) # S
  12. print(first_letter_of_last_string(["cat", "dog", "zebra"])) # z
  13. print(first_letter_of_last_string(["nonsense"])) # n
  14. print(first_letter_of_last_string([])) # None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement