I have this code, from https://stackoverflow.com/a/58314239/15473592
def city(update,context):
list_of_cities = ['Erode','Coimbatore','London', 'Thunder Bay', 'California']
button_list = []
for each in list_of_cities:
button_list.append(InlineKeyboardButton(each, callback_data = each))
reply_markup=InlineKeyboardMarkup(build_menu(button_list,n_cols=1)) #n_cols = 1 is for single column and mutliple rows
bot.send_message(chat_id=update.message.chat_id, text='Choose from the following',reply_markup=reply_markup)
def build_menu(buttons,n_cols,header_buttons=None,footer_buttons=None):
menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)]
if header_buttons:
menu.insert(0, header_buttons)
if footer_buttons:
menu.append(footer_buttons)
return menu
How can I remove a item from list when pressing the button from the list on telegram chat?