首页 > 解决方案 > 搜索元素并返回列表列表中的列表

问题描述

我有以下列表

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 开头的列表。

标签: python

解决方案


您将需要搜索内部列表而不是整个列表列表。

input = '101010'

for lst in list_of_lists:
    if input in lst:
        # Do what you want with the list containing the input

推荐阅读