Im having a little problem with only printing the corresponding abbreviation that is stored in a dictionary
user = input("Enter a Abbreviation: ")
dictionary = {"ADSL": "Application Programming Interface",
"IDE": "Integrated Development Enviroment",
"SDK": "Software Development Kit",
"UI": "User Interface",
"UX": "User eXperience",
"OPP": "Object Oriented Programming"
}
for x in dictionary:
if user in x:
print(user + ":" + " " + dictionary[x])
elif x != dictionary:
print("Abbreviation not found")
This is my output
Enter a Abbreviation: UI
Abbreviation not found
Abbreviation not found
Abbreviation not found
UI: User Interface
Abbreviation not found
Abbreviation not found
I only need the entered abbreviation key value not all the Abbreviation not found outputs, I hope this makes sense
>Solution :
The good point of a dictionary is that is "indexed" so you don’t need to find the key. You are following a array approach, and that is a wrong approach.
user = input("Enter a Abbreviation: ")
dictionary = {"ADSL": "Application Programming Interface",
"IDE": "Integrated Development Enviroment",
"SDK": "Software Development Kit",
"UI": "User Interface",
"UX": "User eXperience",
"OPP": "Object Oriented Programming"
}
if user in dictionary:
print(user + ":" + " " + dictionary[user])
else:
print("Abbreviation not found")
You can find more information about dictionaries here, here and on google. It is very important to know when to use arrays, dictionaries, lists, queues…