Answer the question
In order to leave comments, you need to log in
How to write dictionary processing in VK?
I have a dictionary for a bot like:
hello\hi\hello == Hello\Hello\Hi, how are you?
How to make the bot check for the presence of each value before "==" in the message, and if it is present in it, then give a random answer from the right side
f = open('rad.txt', 'r', encoding='utf-8')
d = {}
for line in f:
d[line[:line.index('==')-1]] = line[3+line.index('=='):].split('\\')
f.close()
response = body
for key in d.keys():
if key in response.lower():
lep=random.choice(d[key])
Answer the question
In order to leave comments, you need to log in
Here is one option:
import random
f = open('rad.txt', 'r', encoding='utf-8')
d = {}
for line in f:
keys = line[:line.index('==') - 1].split('\\')
values = line[3 + line.index('=='):].split('\\')
for key in keys:
d[key] = values
f.close()
response = "привет"
for key in d.keys():
if key in response.lower():
lep = random.choice(d[key])
print(lep)
d
equal to an array with all values[
[
["привет", "хай", "здравствуй"], ["Привет", "Здравствуй", "Привет"]
],
[
Другая фраза
]
]
For по фразам:
For по ключам:
Random по значениям
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question