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

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

    Use isinstance:

    if isinstance(e, list):
    

    If you want to check that an object is a list or a tuple, pass several classes to isinstance:

    if isinstance(e, (list, tuple)):
    

提交回复
热议问题