I have created a dictionary containing majors and corresponding average salaries. I used a for loop to print the keys of the dictionary (being the majors) for a user to pick from. When I run the for
loop at the end of the print
statements, I keep getting the key None
even when specifying to not print None
using an if
statement.
Here is the dictionary I defined:
majors = {
'Management Information Systems': 84219,
'Business': 50670,
'Ecology': 58756,
'Psychology': 40858,
'Sociology' : 58678,
}
And here is the for loop I used to print the keys:
def printMajors():
for key in majors.keys():
if key is not None:
print(key)
I also tried deleting the keys with the value None
using the following (defined before the print
statement):
for key, value in majors.copy().items():
if value is None:
del majors[key]
Output:
Management Information Systems
Business
Ecology
Psychology
Sociology
None // this is unexpected and what I am having trouble with removing
Any help would be much appreciated!