Intro: I have been continuing to follow a textbook on programming (Python, specifically), with the latest 'problem' to solve, being the creation of a 'Phone Number Look-up'.
The brief: The textbook asks the user to create two parallel arrays (7 friend's names & phone numbers) and a search function that steps through the people array and returns both that search result (based on user input) of the friend(s) name(s) and corresponding phone number (note: names and corresponding phone numbers are using identical index positions.
The issue: I have def
a arraysAndSearch
module (that has my people
and phoneNumbers
array
) and used enumerate()
for ease of looping over the people
array and inc. an automatic counter. The program is working, as it's returning full and partial matches of both the person and corresponding index id in the phoneNumbers
array, however I have had issues trying to adapt my code, so that case in-sensitivty is observed.
E.g. searching for 'Katie' returns the two expected values from the people
array and corresponding index id from phoneNumbers
. Searching for 'katie', returns no results, I simply get my error message, that is coded to appear if not arraySearch:
.
Code Extract:
def arraysAndSearch(nameSearch):
people = ['Silviu Ciocanel', 'Katie Trolan', 'Katie MacPherson']
phoneNumbers = ['310-443-7798', '562-905-3343', '310-983-5209']
arraySearch = [people for people in enumerate(people) if nameSearch in people[1]]
for index, nameSearch in arraySearch:
print("Name: ", nameSearch, "\nPhone:", phoneNumbers[index])
if not arraySearch:
print("No matches in phone book :(")
print("****************************")
Is anyone able to offer some guidance as to how I can integrate case in-sensitivity?