Extracting part of an element in a python dictionary
I'm trying to extract only the key of an element in my dictionary but I can only figure out how to append the value.
this is my dictionary:
{"Java": 10, "Ruby": 80, "Python": 65}
I want the output to be the languages with a grade higher than 60. In this case
"Ruby", "Python"
This is my code but with the append()
function, I can only extract the grade.
def my_languages(results):
output = []
for i in results:
if results[i] >= 60:
output.append(results[i])
return output
Thank you all in advance
This is basic Python, please check the docs and some examples online
def my_languages(results):
output = []
for lang, grade in results.items():
if grade >= 60:
output.append(lang)
return output