What is the most efficient way to search nested lists in python?

前端 未结 5 993
刺人心
刺人心 2020-12-01 11:24

I have a list that contains nested lists and I need to know the most efficient way to search within those nested lists.

e.g., if I have

[[\'a\',\'b\         


        
5条回答
  •  执念已碎
    2020-12-01 12:18

    if you just want to know that your element is there in the list or not then you can do this by converting list to string and check it. you can extend this of more nested list . like [[1],'a','b','d',['a','b',['c',1]]] this method is helpful iff you dont know that level of nested list and want to know that is the searchable item is there or not.

        search='d'
        lis = [['a',['b'],'c'],[['d'],'e','f']]
        print(search in str(lis)) 
    

提交回复
热议问题