SamRob85
Badges: 0
Rep:
?
#1
Report Thread starter 7 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 7 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
Back
to top
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

Should the school day be extended to help students catch up?

Yes (96)
27.51%
No (253)
72.49%

Watched Threads

View All