Counting depth or the deepest level a nested list goes to

前端 未结 13 1756
無奈伤痛
無奈伤痛 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条回答
  •  猫巷女王i
    2020-12-02 21:22

    If you're looking for a quick fix

    def getDepth(matrix):
        try:
            len(matrix)
            return getDepth(matrix[0]) + 1
        except:
            return 0
    

提交回复
热议问题