Feb-02-2017, 10:06 AM
(Feb-02-2017, 07:19 AM)landlord1984 Wrote:dict={'a':'aaa','b':'bbb','c':'ccc'} list(dict.keys())Quote:TypeError Traceback (most recent call last)
<ipython-input-60-be97bb392967> in <module>()
----> 1 list(dict.keys())
TypeError: 'list' object is not callable
I want to get a list of the keys of a dictionary for further manipulation. But don't know why this does not work. Somebody here:http://stackoverflow.com/questions/17322...t-indexing
suggested they can do by this way, but it does not work for me.
Another question is: Can I access dictionary by index instead of key?
Thanks,
L
That should work. Since you use
dict
which is a type name as a variable, I can assume that you have a list
variable elwhere in your code, that hides the list()
function.No, you cannot access a dictionary by index. You can at best access the keys by index and then use the keys to access the values. But the key order can change if you add something to the dictionary.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net