pastebin

Paste Search Dynamic
Recent pastes
person check
  1. from collections import deque
  2.  
  3. def person_check(name):
  4.       return name[-1] == 'm'
  5.  
  6. graph = {}
  7. graph["you"] = ["Angela","Jack","Amy"]
  8. graph["Jack"] = ["Adam","Evan"]
  9. graph["Angela"] = ["Evan"]
  10. graph["Amy"] = ["Justin","Bradon"]
  11. graph["Adam"] = []
  12. graph["Evan"] = []
  13. graph["Justin"] = []
  14. graph["Bradon"] = []
  15.  
  16. def search(name):
  17.     search_queue = deque()
  18.     search_queue += graph[name]
  19.     searched = []
  20.     while search_queue:
  21.         person = search_queue.popleft()
  22.         if not person in searched:
  23.             if person_check(person):
  24.                 print person + " has an Apple!"
  25.                 return true
  26.             else:
  27.                 search_queue += graph[person]
  28.                 searched.append(person)
  29.     return false
  30.  
  31. search("you")
  32.  
Parsed in 0.008 seconds