Counting depth or the deepest level a nested list goes to

前端 未结 13 1730
無奈伤痛
無奈伤痛 2020-12-02 21:04

A have a real problem (and a headache) with an assignment...

I\'m in an introductory programming class, and I have to write a function that, given a list, will retur

13条回答
  •  Happy的楠姐
    2020-12-02 21:38

    Did it in one line of python :)

    enjoy

    def f(g,count=0): return count if not isinstance(g,list) else max([f(x,count+1) for x in g])
    

提交回复
热议问题