Python Forum
Why list(dict.keys()) does not work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why list(dict.keys()) does not work?
#1
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
Reply


Messages In This Thread
Why list(dict.keys()) does not work? - by landlord1984 - Feb-02-2017, 07:19 AM
RE: Why list(dict.keys()) does not work? - by wavic - Feb-02-2017, 07:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extending list doesn't work as expected mmhmjanssen 2 238 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,442 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Beginner: Code not work when longer list raiviscoding 2 887 May-19-2023, 11:19 AM
Last Post: deanhystad
  How to work with list kafka_trial 8 2,113 Jan-24-2023, 01:30 PM
Last Post: jefsummers
  Membership test for an element in a list that is a dict value for a particular key? Mark17 2 1,271 Jul-01-2022, 10:52 PM
Last Post: Pedroski55
  Are list/dict comprehensions interpreted really sequentially? anata2047 3 1,504 May-31-2022, 08:43 PM
Last Post: Gribouillis
  Updating nested dict list keys tbaror 2 1,320 Feb-09-2022, 09:37 AM
Last Post: tbaror
  Loop Dict with inconsistent Keys Personne 1 1,651 Feb-05-2022, 03:19 AM
Last Post: Larz60+
  Remove empty keys in a python list python_student 7 3,179 Jan-12-2022, 10:23 PM
Last Post: python_student
  Create Dict from multiple Lists with duplicate Keys rhat398 10 4,183 Jun-26-2021, 11:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020