Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the get_shortest_name function which is passed a list of strings as a p

ID: 3754658 • Letter: C

Question

Complete the get_shortest_name function which is passed a list of strings as a parameter. The function returns the word in the list which has the least characters (i.e the shortest name). If two or more words in the list have the same number of characters as the shortest name, the function should return the first name from the start of the list which has the least characters. If the parameter list is empty, the function should return an empty string. For example: Test Result print ("1.", get_shortest_name(["Candide", "Jessie", "Kath",1. K "Amity" "Raeanne"])) ath Answer: (penalty regime: 0 %) 1 |def get_shortest name(list_):

Explanation / Answer

def get_shortest_name(list_):
smallest_name =""
if len(list_)==0:
return smallest_name


alphabet_count =[len(name) for name in list_]
smallest_length = min(alphabet_count)

for name in list_:
if(len(name)==smallest_length):
smallest_name = name
break

return smallest_name
  
  

print ("1.", get_shortest_name(['bb','sdfsd','aa','dsfdsd']))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote