NoneType 개체는 반복 할 수 없습니다.

TheDude

Dijkstra의 알고리즘에 대한 클래스를 작성하는 작업이 있습니다. Dijkstra 클래스를 편집 할 수는 없지만 :

class Dijkstra():
# initialize with a string containing the root and a
# weighted edge list
def __init__(self, in_string):
    self.root, self.nnodes, self.adj_list = self.convert_to_adj_list(in_string)
    self.nodes = [Node(i) for i in range(self.nnodes)]
    self.nodes[self.root].key = 0
    self.heap = MinHeap(self.nodes)
# the input is expected to be a string 
# consisting of the number of nodes
# and a root followed by 
# vertex pairs with a non-negative weight
def convert_to_adj_list(self, in_string):
    nnodes, root, edges = in_string.split(';')
    root = int(root)
    nnodes = int(nnodes)
    adj_list = {}
    edges = [ map(int,wedge.split()) for wedge in edges.split(',')]
    for u,v,w in edges:
        (adj_list.setdefault(u,[])).append((v,w))
    for u in range(nnodes):
        adj_list.setdefault(u,[])

이것은 내 문제입니다.

string = '3; 0; 1 2 8, 2 0 5, 1 0 8, 2 1 3'
print(Dijkstra(string))
Traceback (most recent call last):
  File "<pyshell#321>", line 1, in <module>
    print(Dijkstra(string))
  File "C:\Users\TheDude\Downloads\dijkstra.py", line 71, in __init__
    self.root, self.nnodes, self.adj_list = self.convert_to_adj_list(in_string)
TypeError: 'NoneType' object is not iterable

append의 반환 값을 할당 합니까? class Djikstra()읽기를 위해 탱크를 편집하지 않고 어떻게 고칠 수 있습니까 ?

tobias_k

과제를 위해

    self.root, self.nnodes, self.adj_list = self.convert_to_adj_list(in_string)

작동 convert_to_adj_list하려면 세 가지 변수로 풀릴 세 값의 튜플을 반환해야합니다. 그러나 귀하의 메서드는 아무것도 반환하지 않으므로 암시 적으로 반환 None합니다. convert_to_adj_list방법을 다음과 같이 변경 하면 작동합니다.

def convert_to_adj_list(self, in_string):
    ... your code ...
    return root, nnodes, adj_list

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

'NoneType'개체는 반복 할 수 없습니다.

분류에서Dev

to_representation 오류 : 'NoneType'개체는 반복 할 수 없습니다.

분류에서Dev

to_representation 오류 : 'NoneType'개체는 반복 할 수 없습니다.

분류에서Dev

Python-TypeError : 'NoneType'개체는 반복 할 수 없습니다.

분류에서Dev

NoneType 객체는 반복 할 수 없습니다.

분류에서Dev

'NoneType'개체를 해결할 수 없음은 반복 할 수 없습니다 .TypeError

분류에서Dev

ExtraTreesClassifier에서 NoneType으로 표시되는 feature_importances_ : TypeError : 'NoneType'개체는 반복 할 수 없습니다.

분류에서Dev

오류 : read_sql 일 때 'NoneType'개체를 반복 할 수 없습니다.

분류에서Dev

Python : 반복없이 " 'Nonetype'은 반복 할 수 없습니다."

분류에서Dev

TypeError : 'NoneType'객체는 반복 할 수 없지만 여전히 목록을 반복하는 것 같습니다.

분류에서Dev

내 코드에서 TypeError : 'NoneType'개체가 반복 할 수없는 이유

분류에서Dev

TypeError : 이전 값을 덮어 쓸 때 'NoneType'개체를 반복 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 구독 할 수 없습니다 (PYTHON).

분류에서Dev

NoneType 개체는 구독 할 수 없습니다.

분류에서Dev

Django Middleware- 'AnonymousUser'개체는 반복 할 수 없습니다.

분류에서Dev

TypeError : 'numpy.bool_'개체는 반복 할 수 없습니다.

분류에서Dev

/ register / 'AnonymousUser'개체의 TypeError는 반복 할 수 없습니다.

분류에서Dev

Django 'logout'TypeError : 'AnonymousUser'개체는 반복 할 수 없습니다.

분류에서Dev

TypeError : 'UniqueConstraint'개체는 Django에서 반복 할 수 없습니다.

분류에서Dev

'builtin_function_or_method'개체는 반복 할 수 없습니다.

분류에서Dev

'builtin_function_or_method'개체는 반복 할 수 없습니다.

분류에서Dev

TypeError : '외계인'개체는 반복 할 수 없습니다.

분류에서Dev

두 합계 해결 : NoneType '은 반복 할 수 없습니다.

분류에서Dev

TelegramBot 오류입니다. TypeError : 'NoneType'개체는 구독 할 수 없습니다.

분류에서Dev

TypeError : nonetype을 확인할 때 'NoneType'개체를 구독 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 호출 할 수없는 Tensorflow입니다.

분류에서Dev

TypeError : 'NoneType'개체는 호출 할 수없는 Tensorflow입니다.

분류에서Dev

Nonetype 객체는 사전을 반복 할 때 'items'속성이 없습니다.

Related 관련 기사

  1. 1

    'NoneType'개체는 반복 할 수 없습니다.

  2. 2

    to_representation 오류 : 'NoneType'개체는 반복 할 수 없습니다.

  3. 3

    to_representation 오류 : 'NoneType'개체는 반복 할 수 없습니다.

  4. 4

    Python-TypeError : 'NoneType'개체는 반복 할 수 없습니다.

  5. 5

    NoneType 객체는 반복 할 수 없습니다.

  6. 6

    'NoneType'개체를 해결할 수 없음은 반복 할 수 없습니다 .TypeError

  7. 7

    ExtraTreesClassifier에서 NoneType으로 표시되는 feature_importances_ : TypeError : 'NoneType'개체는 반복 할 수 없습니다.

  8. 8

    오류 : read_sql 일 때 'NoneType'개체를 반복 할 수 없습니다.

  9. 9

    Python : 반복없이 " 'Nonetype'은 반복 할 수 없습니다."

  10. 10

    TypeError : 'NoneType'객체는 반복 할 수 없지만 여전히 목록을 반복하는 것 같습니다.

  11. 11

    내 코드에서 TypeError : 'NoneType'개체가 반복 할 수없는 이유

  12. 12

    TypeError : 이전 값을 덮어 쓸 때 'NoneType'개체를 반복 할 수 없습니다.

  13. 13

    TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

  14. 14

    TypeError : 'NoneType'개체는 구독 할 수 없습니다 (PYTHON).

  15. 15

    NoneType 개체는 구독 할 수 없습니다.

  16. 16

    Django Middleware- 'AnonymousUser'개체는 반복 할 수 없습니다.

  17. 17

    TypeError : 'numpy.bool_'개체는 반복 할 수 없습니다.

  18. 18

    / register / 'AnonymousUser'개체의 TypeError는 반복 할 수 없습니다.

  19. 19

    Django 'logout'TypeError : 'AnonymousUser'개체는 반복 할 수 없습니다.

  20. 20

    TypeError : 'UniqueConstraint'개체는 Django에서 반복 할 수 없습니다.

  21. 21

    'builtin_function_or_method'개체는 반복 할 수 없습니다.

  22. 22

    'builtin_function_or_method'개체는 반복 할 수 없습니다.

  23. 23

    TypeError : '외계인'개체는 반복 할 수 없습니다.

  24. 24

    두 합계 해결 : NoneType '은 반복 할 수 없습니다.

  25. 25

    TelegramBot 오류입니다. TypeError : 'NoneType'개체는 구독 할 수 없습니다.

  26. 26

    TypeError : nonetype을 확인할 때 'NoneType'개체를 구독 할 수 없습니다.

  27. 27

    TypeError : 'NoneType'개체는 호출 할 수없는 Tensorflow입니다.

  28. 28

    TypeError : 'NoneType'개체는 호출 할 수없는 Tensorflow입니다.

  29. 29

    Nonetype 객체는 사전을 반복 할 때 'items'속성이 없습니다.

뜨겁다태그

보관