How to check if an element of a list is a list (in Python)?
Question: 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 a list, what can I
replace _aValidList_ in the following code with?

    
    
    for e in list:
        if e == aValidList:
            return True
    

Is there a special import to use? Is there a best way of checking if a
variable/element is a list?


Answer: Use [`isinstance`](http://docs.python.org/library/functions.html#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)):
    

