I intend to apply a function to a variable. I do not know beforehand if the incoming variable will be a list of list or a single list. e.g
var_name = [a, b, c]
or
var_name = [[a,b,c], [d,e,f], [h,i,j]]
The list of list could contain as many lists as possible. How do I go about verifying if the variable is a list or list of lists. I intend to apply a function depending on the type. I tried to use len(var_name) but the length for list will be the number of items in single list while for list of lists, it is the number of lists in the list of lists.
what I am trying to achieve is this:
#function for list
def apply_val(lst):
do something with single list
#function for list of list
def apply_val2(lst):
do something with list of lists
var_name = single_list or list_of_lists
if var_name == single list
apply_val(single_list)
else:
apply_val(list_of_lists)
How do I check if the var_name is a list or list of lists?
if isinstance(arg[0], str):. If not assume it's a list.