Word association - python Watch
Page 1 of 1
I am trying to create a word association program in python. So far I have done this
However what I want to do is to have each string in the list have it's own list and so on, how would you do this.
Code:
a= ["hello","greeting"] b=input("Hello") a.append(b) print(a)
0
reply
Report
#2
You could use dictionaries to associate each word with a list of other words?
Code:
words = { "hello" : ["greeting"], "greeting" : ["hello"] } b = raw_input("hello") # Add input value to list of words associated with "hello" words["hello"].append(b) # Also add "hello" into the list of words associated with the input value if b in words: words[b].append("hello") else: words[b] = ["hello"]
0
reply
X
Page 1 of 1