Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- connections_line = "John is connected to Bryant, Debra, Walter.John likes to play The Movie: The Game, The Legend of Corgi, Dinosaur Diner."
- def connections(lst):
- # start with an empty graph
- graph = {}
- # split the input string to individual words
- split_line = connections_line.split()
- # grab the first item in the list(the user) and assign it to a variable
- key = split_line.pop(0)
- connections_lst = []
- # iterate through the split list
- for word in split_line:
- # if word doesn't match the ones in the 'if' condition, append word to empty connections_lst
- if word != "is" and word != "connected" and word != "to" and word != "likes" and word != "play":
- connections_lst.append(word)
- # assign connections_lst as value to user
- graph[key] = [connections_lst]
- return graph
- print connections(connections_line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement