Home>

just began to study this algorithm. I can not understand why when I call a function -I get an error. It seems to do everything correctly. Direct in the right direction :)

From Collections Import Deque
"" "Implementation of graphs" ""
Graph= {}
Graph ["You"]= ["Alice", "Bob", "Claire", "Mam"]
DEF PERSON_IS_SELLER (Name):
    RETURN NAME [-1]== "M"
DEF Search (Name):
    Search_Queue= deque ()
    Search_Queue += Graph [Name]
    searchhed= [] # array to track proven data
    While Search_Queue:
        person= search_queue.popleft ()
        If Not Person in Search: # The check continues only if the data in the array of searcehed data is not lit up
            IF Person_is_Seller (Person):
                Print (Person + "IS A Mango Seller")
                Return True.
            ELSE:
                Search_Queue += Graph [Person] # Data marked as proven
                searched.append (Person) # Data added to the search array
            Return False
Traceback (MOST Recent Call Last):
  File "C: \ Users \ vladik \ desktop \ New folder \ graph.py", Line 32, in <
Module >
    Search ("You")
  File "C: \ users \ vladik \ desktop \ New folder \ graph.py", line 28, in search
    Search_Queue += Graph [Person]
KEYERROR: 'ALICE'

can not understand why it is not looking for values ​​in the created column. Tell me how to implement this search in the graphs.

So you have only one element of the GRAPH dictionary ["You"] is filled, and the rest who will fill out? Well, there Graph [Alice] and all other

CrazyElf2021-04-07 19:00:42

For sure! Thanks a lot!

yOz2021-04-07 19:13:06
Trends