Question

In: Computer Science

in Python 3, I need to search a dictionary for the matching key while ignoring case...

in Python 3, I need to search a dictionary for the matching key while ignoring case of the string and the key. then print the dictionary item in it's original case.

here is the code I have so far but the compiler isn't liking that the name string is lowercase

```
dictionary = {"Dan Smith": {"street":"285 Andover Lane", "city":"Pompano Beach", "state":"FL", "zip":"33060"},"Parker Brady": {"street":"7416 Monroe Ave.", "city":"Windsor", "state":"CT", "zip":"07302"}}

name ="dan smith"

line= dict(filter(lambda item: name.lower() in item[0], dictionary.items()))

print("Street:%5s "% line[name]['street'])
print("City:%5s" % line[name]['city'])
print("State:%5s "% line[name]['state'])
print("Zip Code:%5s "% line[name]['zip'])
```

output should be

Street: 285 Andover Lane

City: Pompano Beach

State: FL

Zip Code: 33060

Solutions

Expert Solution

code:

output :

raw_coode :

#given data
dictionary = {"Dan Smith": {"street":"285 Andover Lane",
"city":"Pompano Beach", "state":"FL",
"zip":"33060"},
"Parker Brady": {"street":"7416 Monroe Ave.",
"city":"Windsor", "state":"CT",
"zip":"07302"}}


name ="dan smith"
#using comprehension for changing to lower case
line = {i.lower(): j for i,j in dictionary.items()}

#displaying required details
print("Street: %5s"%line[name]['street'])
print("City:%5s" % line[name]['city'])
print("State:%5s "% line[name]['state'])
print("Zip Code:%5s "% line[name]['zip'])

**do comment for queries and rate me up****


Related Solutions

I have a python dictionary with the following format Key Type Value January str ['January 01...
I have a python dictionary with the following format Key Type Value January str ['January 01 2020', 'January 02 2019', 'January 03 2018'] June str ['June 04 2018', 'June 05 2018', 'June 06 2016] August str ['Augsut 07 2016', 'August 08 2016'] How do return the following conclusion with python code? January has the most day (1) in 2020 January has the most day (1) in 2019 June has the most days (2) in 2018 August has the most days...
Using python. 1. How to create a dictionary that has an integer as a key and...
Using python. 1. How to create a dictionary that has an integer as a key and a byte as a value? the dictionary keys must contain integers from 0 to 255. It should be similar to UTF-8. When we enter an integer, it should return 1 byte. 2. Create a function when a user gives 1 byte, it should return the key from the previous dictionary.
python pls create a function party_place: that search the dictionary and figure out where they party...
python pls create a function party_place: that search the dictionary and figure out where they party in that day. For example def party_place(dict2: dict, date: (int,int,int)): dict1= {'fire1': {(2000,5,20,480) : ('Aaron', 25, 300, ( 0, 300)), (2000,5,20,720) : ('Baily', 45, 1500, (1500,500)), (2000,5,21,490) : ('Aaron', 35, 500, (1300,500)) }, 'fire2': {(2000,5,20,810) : ('Baily', 45, 1400, (600,1600)), (2000,5,20,930) : ('Baily', 43, 1800, ( 0, 0)) }} output print(party_place(dict1, (2000,5,20,720)) = ['fire1', 'fire2'] print(party_place(dict1, (2000,5,21,720)) = ['fire1'] print(party_place(dict1, (2000,5,22,720)) = []
Write a python program that keeps names and email addresses in a dictionary as key-value pairs....
Write a python program that keeps names and email addresses in a dictionary as key-value pairs. The program should display a menu that lets the user look up a person’s email address, add a new name and email address, change an existing email address, and delete an existing name and email address. The program should bind the dictionary and save it to a file when the user exits the program. Each time the program starts, it should retrieve the dictionary...
Creating a Dictionary (python 3) Description Larry is an immigrant in the USA and has a...
Creating a Dictionary (python 3) Description Larry is an immigrant in the USA and has a hard time understanding English there. So he decides to make a software that will tell him the synonyms of the word that he types. He has asked you for help. Remember, you will first need to choose a data structure that you will use to store the information about the words. You can use lists or dict or tuple or anything else for this...
(Python) I want to use a function called level() that takes a dictionary. Here is a...
(Python) I want to use a function called level() that takes a dictionary. Here is a dictionary with people's job and skill level. dict1 = {'Jame': {'Cleaning': 5, 'Tutoring': 2, 'Baking': 1},Pam': {'Plumbing': 2, 'Cleaning': 5}) like if I called level(dict1), the output will return {'Pam', 'James'} It finds the people's average skill level like for Pam is (2+5)/2=3.5 and sorted descending. How do I do that and how do I do it in only one return statement(using comprehension or...
How would I create a nested dictionary given a csv file in Python? Say I want...
How would I create a nested dictionary given a csv file in Python? Say I want to make a dictionary that read {'country':{'China':'Fit', 'China':'Overweight', 'USA': 'Overweight', 'USA': 'Fit', 'England':'Fit'...}, 'category':{'Asian':'Fit', 'Caucasian': 'Overweight', 'Caucasian':'Overweight', 'Asian': 'Fit', 'Middle Eastern': 'Fit'...}} given a file that had country category Weight China Asian Fit China Caucasian Overweight USA Caucasian Overweight USA Asian Fit England Middle Eastern Fit... ... And so on in the file.
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName,...
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName, courses = None): The “id”, “firstName” and “lastName” parameters are to be directly assigned to member variables (ie: self.id = id) The “courses” parameter is handled differently. If it is None, assign dict() to self.courses, otherwise assign courses directly to the member variable. Note: The “courses” dictionary contains key/value pairs where the key is a string that is the course number (like “course1”) and...
Short Python 3 questions a. Create a dictionary that maps the first n counting numbers to...
Short Python 3 questions a. Create a dictionary that maps the first n counting numbers to their squares. Assign the dictionary to the variable squares b. Given the list value_list, assign the number of nonduplicate values to the variable distinct_values
REQUIREMENT #3 Okay, I have a case study I need to complete by the end of...
REQUIREMENT #3 Okay, I have a case study I need to complete by the end of this week but I am stuck. Plus, I need to make sure that I am doing this correctly. It is a layered challenge. I will have to send the study in pieces because I could not attach the actual document.    Prepare a trial balance for July.     During its first month of operation, the Quick Tax Corporation, which specializes in tax preparation,              ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT