python - 如何仅打印文件的特定部分
问题描述
所以我有一个名称列表,例如:
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 )
有任何想法吗?
解决方案
我不完全确定您的目标是什么,但是您可以使用嵌套字典策略,其中品牌是第一级的键,而像“武器”这样的标签是第二级。例如
myBrands={'brand1':{'weapon':brandOneWeapon}}
因此,当您调用 myBrands 时,您可以使用密钥来获取您想要的内容。
currentWeapon=myBrands['brand1']['weapon']
print(currentWeapon)
推荐阅读
- javascript - 带有 HTML5 的 LED 时钟动画
- apache-spark-sql - Pyspark:如何将值附加到列的开头?
- selenium - isDisplayed 未定位元素
- android - 无法从 firebase 检索 DisplayName 名称和 PhotoUrl,总是返回 null,Flutter
- javascript - useCallback 有语义保证吗?
- react-native - 是否可以在本机反应中更改滚动条颜色
- angular - agggrid valueGetter/valueSetter 超出组件范围
- jmespath - 从 JMESPath 表达式中删除方括号
- performance - 对矩阵元素求幂的两种方法的比较
- r - 在 R 中使用 geom_linerange 在 ggplots 中垂直使用位置闪避问题