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

前端 未结 5 950
别跟我提以往
别跟我提以往 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 09:53

    you can simply write:

    for item,i in zip(your_list, range(len(your_list)):
    
        if type(item) == list:
            print(f"{item} at index {i} is a list")
    

提交回复
热议问题