小编Ash*_*dud的帖子

尽管转换为列表,但获取'dict_keys'对象仍不支持索引

我正在使用Python 3,尽管已经转换为列表,但我似乎无法运行我的程序.

这是函数调用:

path = euleriancycle(edges)
Run Code Online (Sandbox Code Playgroud)

这是我使用keys方法的地方:

def euleriancycle(e):
    currentnode = list[e.keys()[0]]
    path = [currentnode]
Run Code Online (Sandbox Code Playgroud)

我尝试在没有类型转换的情况下运行它来列出并得到此错误.在翻阅了这个网站和类似的查询之后,我按照建议的解决方案和输入列表但没有用.我得到了同样的错误.

这是错误跟踪:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-56-356b905111a9> in <module>()
     45             edges[int(edge[0])] = [int(edge[1])]
     46 
---> 47 path = euleriancycle(edges)
     48 print(path)

<ipython-input-56-356b905111a9> in euleriancycle(e)
      1 def euleriancycle(e):
----> 2     currentnode = list[e.keys()[0]]
      3     path = [currentnode]
      4 
      5     while true:

TypeError: 'dict_keys' object does not support indexing
Run Code Online (Sandbox Code Playgroud)

python dictionary python-3.x jupyter-notebook

1
推荐指数
1
解决办法
8905
查看次数

标签 统计

dictionary ×1

jupyter-notebook ×1

python ×1

python-3.x ×1