I know how to convert a dictionary into an list in Python, but somehow when I try to get, say, the sum of the resulting list, I get the error \'dict_values\' object is
By assigning dict.values()
to a list you are not converting it to a list; you are just storing it as dict_values (may be an object). To convert it write list=list(dict.values())
. Now even while printing the list
you will get the list elements and not dict_values(......)
.
And as mentioned before don't use Python built-in names as your variable names; it may cause conflicts during execution and confusion while reading your code.