Created
November 15, 2023 16:05
-
-
Save JTSGIT/5fa00796bdc59cca7482c813099301b6 to your computer and use it in GitHub Desktop.
Kata4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def instructorWithLongestName(instructors): | |
""" | |
This function receives a list of instructor dictionaries and returns the one with the longest name. | |
""" | |
# Initialize the instructor with the longest name so far | |
longest_instructor = instructors[0] | |
# Iterate through the list of instructors to find the one with the longest name | |
for instructor in instructors: | |
if len(instructor["name"]) > len(longest_instructor["name"]): | |
longest_instructor = instructor | |
return longest_instructor | |
# Testing the function with different inputs | |
print(instructorWithLongestName([ | |
{"name": "Samuel", "course": "iOS"}, | |
{"name": "Jeremiah", "course": "Data"}, | |
{"name": "Ophilia", "course": "Web"}, | |
{"name": "Donald", "course": "Web"} | |
])) | |
print(instructorWithLongestName([ | |
{"name": "Matthew", "course": "Data"}, | |
{"name": "David", "course": "iOS"}, | |
{"name": "Domascus", "course": "Web"} | |
])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment