python - 搜索元素并返回列表列表中的列表
问题描述
我有以下列表
list_of_lists= [['ID', 'Last', 'First', 'GradYear', 'GradTerm', 'DegreeProgram'], ['101010', 'Lee', 'Shane', '2019', 'Spring', 'MSA'], ['101020', 'Zhang', 'Eve', '2019', 'Summer', 'MSSD'], ['101030', 'Anthony', 'Daisy', '2020', 'Fall', 'MSBA']]
现在,当我输入 eg10
时,我想检索“所有包含 ID 以 10 开头的列表。
解决方案
您将需要搜索内部列表而不是整个列表列表。
input = '101010'
for lst in list_of_lists:
if input in lst:
# Do what you want with the list containing the input
推荐阅读
- javascript - 使用 javascript 事件侦听器更改按钮的文本
- javascript - 如何将带有对象列表的数据对象传递给控制器
- python - 在python中将输出写入CSV
- python - 自动获取创建日期并将文件重命名为它
- apache-zeppelin - 通过 Zeppelin API 创建解释器时无法创建新笔记本?
- microsoft-graph-api - Microsoft graph,根据appId获取应用权限
- android - 收到html格式而不是json
- pandas - 在 groupby 操作中选择字符串和数字混合的数据框列
- robotc - 如何编程 vex 爪机器人进行线路跟踪?
- php - PHP中如何防止XSS,当需要解析脏markdown来清理markdown内容时