Skip to content

Instantly share code, notes, and snippets.

@JTSGIT
Created November 15, 2023 16:05
Show Gist options
  • Save JTSGIT/5fa00796bdc59cca7482c813099301b6 to your computer and use it in GitHub Desktop.
Save JTSGIT/5fa00796bdc59cca7482c813099301b6 to your computer and use it in GitHub Desktop.
Kata4.py
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