Should the code be a list or dict_key?

Why It is not correct to do with the below code:
users = list(user_ids)

I have printed out it and it is matching with the needs.

1 Like

Following the instructions, the following is the expected output for print (users)

dict_keys(['pythonGuy', 'keysmithKeith', 'lyleLoop', 'teraCoder', 'samTheJavaMaam'])

whereas your code gives the following:

['pythonGuy', 'keysmithKeith', 'lyleLoop', 'teraCoder', 'samTheJavaMaam']
object.keys()

is not a proper list, per se, but a dict_keys object.

3 Likes

maksagery , I made the same mistake, mate.

Check the following in the description:

Dictionaries also have a “ .keys() ” method that returns a “ dict_keys ” object.

1 Like

Thank you for the hint mtf !

user_ids = {"teraCoder": 100019, "pythonGuy": 182921, "samTheJavaMaam": 123112, "lyleLoop": 102931, "keysmithKeith": 129384}

print(user_ids.keys())
print(list(user_ids.keys()))
print(list(user_ids))

result

dict_keys(['pythonGuy', 'teraCoder', 'keysmithKeith', 'samTheJavaMaam', 'lyleLoop'])
['pythonGuy', 'teraCoder', 'keysmithKeith', 'samTheJavaMaam', 'lyleLoop']
['pythonGuy', 'teraCoder', 'keysmithKeith', 'samTheJavaMaam', 'lyleLoop']

can someone explain what the different for this code…?
i mean, which one most suitable to use or most common…?

thanks