Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. connections_line = "John is connected to Bryant, Debra, Walter.John likes to play The Movie: The Game, The Legend of Corgi, Dinosaur Diner."
  2.  
  3. def connections(lst):
  4.  
  5.     # start with an empty graph
  6.     graph = {}
  7.  
  8.     # split the input string to individual words
  9.     split_line = connections_line.split()
  10.  
  11.     # grab the first item in the list(the user) and assign it to a variable
  12.     key = split_line.pop(0)
  13.  
  14.     connections_lst = []
  15.  
  16.     # iterate through the split list
  17.     for word in split_line:
  18.  
  19.         # if word doesn't match the ones in the 'if' condition, append word to empty connections_lst
  20.             if word != "is" and word != "connected" and word != "to" and word != "likes" and word != "play":
  21.                 connections_lst.append(word)
  22.  
  23.     # assign connections_lst as value to user
  24.     graph[key] = [connections_lst]
  25.     return graph
  26.  
  27.    
  28.  
  29. print connections(connections_line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement