Word association - python Watch

SamRob85
Badges: 0
Rep:
?
#1
Report Thread starter 4 years ago
#1
I am trying to create a word association program in python. So far I have done this
Code:
a= ["hello","greeting"]
b=input("Hello")
a.append(b)
print(a)
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.
0
reply
Planto
Badges: 16
Rep:
?
#2
Report 4 years ago
#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

Quick Reply

Attached files
Write a reply...
Reply
new posts
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Do you give blood?

Yes (35)
11.15%
I used to but I don't now (11)
3.5%
No, but I want to start (113)
35.99%
No, I am unable to (69)
21.97%
No, I chose not to (86)
27.39%

Watched Threads

View All