-2

所以我有一个名称列表,例如:

XX1
XX2
XX3
XZ1
XZ2 

按品牌划分,例如:

Atlas

    XX1
    XX2
    XX3

Tediore

    XZ1
    XZ2

在此之后,我只想打印用户选择的所请求品牌的特定武器:

elif text.startswith('/weapon'):
    keyboard = InlineKeyboardMarkup(inline_keyboard =[[InlineKeyboardButton(text='Atlas', callback_data='Atlas')],
                                                      [InlineKeyboardButton(text='Tediore', callback_data='tediore')],
                                                      [InlineKeyboardButton(text='DAHL', callback_data='DAHL')],])
bot.sendMessage(msg_data['chat_id'],"Select the brand ?",reply_markup = keyboard )

有任何想法吗?

4

1 回答 1

1

我不完全确定您的目标是什么,但是您可以使用嵌套字典策略,其中品牌是第一级的键,而像“武器”这样的标签是第二级。例如

myBrands={'brand1':{'weapon':brandOneWeapon}}

因此,当您调用 myBrands 时,您可以使用密钥来获取您想要的内容。

currentWeapon=myBrands['brand1']['weapon']
print(currentWeapon)
于 2019-11-26T21:10:20.177 回答