How to check if an element of a list is a list (in Python)?

前端 未结 5 965
别跟我提以往
别跟我提以往 2020-12-25 09:41

If we have the following list:

list = [\'UMM\', \'Uma\', [\'Ulaster\',\'Ulter\']]

If I need to find out if an element in the list is itself

5条回答
  •  庸人自扰
    2020-12-25 10:00

    Probably, more intuitive way would be like this

    if type(e) is list:
        print('Found a list element inside the list') 
    

提交回复
热议问题