Code is for Python 3.3 Name Information Define a function called nameinfo which
ID: 3580716 • Letter: C
Question
Code is for Python 3.3
Name Information Define a function called nameinfo which takes a list, whose elements are strings representing peoples' names, as an argument and returns two values: value 1 = the number of characters in the longest name(s) in the list value 2 = a list of ALL the names having the longest length sample results returned nameinfo(['Zeynep', 'Ali', 'Hadi', 'Nicholas', 'Yahia']) ==> (8, ['Nicholas']) nameinfo(['Mohammed', 'Haley', 'Elizabeth', 'Aidan', 'Natalia', 'Nathaniel', 'Jonathan', 'Aman']) ==>(9, ('Eliz abeth', 'Nathaniel']) nameinfo(['Stephen', 'Symone', 'Melany', 'Shengxu', 'Lucas', 'Yuhang', 'Edmund', 'Juan', 'Belle']) == > (7, ['Stephen', 'Shengxu', 'Brandon']) nameinfo([]) ==> (0, []) In [7]: def nameinfo(ListOfNames): """Returns two values: first value m length of the longest name(s) in ListOfNames second value= a list containing ALL the names of maximal length"""Explanation / Answer
def nameinfo(ListOfNames):
ans=[]
mx=0
for kk in ListOfNames:
ln = len(kk)
if(ln>mx):
mx=ln
ans=[kk]
elif(ln==mx):
ans.append(kk)
return (mx,ans)
print(nameinfo(['zeynep','ali','nicholas','yahia','aaaaaaaa']))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.