Feb-02-2017, 10:53 AM
(This post was last modified: Feb-02-2017, 10:55 AM by landlord1984.)
(Feb-02-2017, 07:55 AM)wavic Wrote: my_dict = {'a':'aaa','b':'bbb','c':'ccc'}
l = list(my_dict.keys())
print(l)
print(my_dict.keys())
Weird....The script code works. But those in console still does not return "TypeError: 'list' object is not callable". Anyway, I am writing in a script, jsut sometimes do quick testing in console
(Feb-02-2017, 10:06 AM)Ofnuts Wrote:(Feb-02-2017, 07:19 AM)landlord1984 Wrote:That should work. Since you usedict={'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 callableI 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, Ldict
which is a type name as a variable, I can assume that you have alist
variable elwhere in your code, that hides thelist()
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.
Ok. I see. I think a need to give up using dictionary in this case. I want to do some manipulation of insert and remove.