Hello, I’m trying to understand the difference between accessing values using .values
versus using the dictionary name directly. Below I will provide my own code versus codecademy’s sotution. Both of them work and I just want to know why. here is the link to the challenge (it’s challenge number 4): https://www.codecademy.com/courses/learn-python-3/articles/python-code-challenges-dictionaries.
My code:
def values_that_are_keys(my_dictionary):
values_list = []
for value in my_dictionary.values():
if value in my_dictionary.keys():
values_list.append(value)
return values_list
Codecademy’s solution:
def values_that_are_keys(my_dictionary):
value_keys = []
for value in my_dictionary.values():
if value in my_dictionary:
value_keys.append(value)
return value_keys
Thank you for all your help in advance!