B
B
Belavor2020-02-06 17:06:40
Python
Belavor, 2020-02-06 17:06:40

How to implement if message.text == {array} so that if elif is not written for each number?

telebot python telegram bot.....

there is a certain array

code = [
     ["11072"],
     ["018"],
     ["13072", "13079"], 
     ["0"],
     ["11070", "11012",  "11219", "11071"],
     ["11464","11496", "11408"],
     ["136"]
     ]

and
bot.message_handler(content_types=["text"])
def repeat_all_messages(message):
     chatid = message.chat.id
     if message.text == '13072':
          bot.send_message(chatid, f"code is {message.text}")
     else:
          bot.send_message(chatid, message.text)


is it possible to make some kind of loop for this?
to write if else for each number
ps: I have been in python for 2 days
pss: I have not reached the databases yet

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-02-06
@Belavor

code = [
     ["11072"],
     ["018"],
     ["13072", "13079"], 
     ["0"],
     ["11070", "11012",  "11219", "11071"],
     ["11464","11496", "11408"],
     ["136"]
     ]
if message.text in ['13072','1111','2222','3333']:
   print('ok')
if message.text in [j for i in code for j in i]:
   print('cool')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question