I am trying to create a dictionary that can be called upon for the respective data. My issue is that I have to account for case sensitivity in the user input. The dictionary is stored within the function main(). The goal of this program is for the user to be able to use the function's output (in this case stored in 'dict1') and enter keys to get the respective data. This is a simplified version of my program right now.
Due to restrictions in place, the user must use the Shell to assign the variable and c
def main(data_source_file):
### For sake of brevity, imagine I extract the data from the file and convert to a dict
### The final output is below
dict1 = {'Africa': [1,2], 'Asia': [3,4], 'Americas', [5,6]}
return dict1
>>> dict1 = main('datafile')
>>> dict1["Africa"]
[1,2]
>>> dict1["AFRICA"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'AFRICA'
I'm familiar with the idea of capitalisation in strings and lists, however I am unsure how to apply it to a key entry by the user.
My first thought was an approved entry list e.g. ["AFRICA","africa","Africa", (ect)] However I want to be able to account for inputs such as "AFriCA", so an approved list would take too long to write for each dictionary key.