better way of handling nested list
- by laspal
Hi,
I have list
my_list = [ [1,2,3,4,5,6], [1,3,4],[34,56,56,56]]
for item in my_list:
var1,var2,var3,var4,var5,var6 = None
if len(item) ==1:
var1 = item[0]
if len(item) == 2:
var1 = item[0]
var2 = item[1]
if len(item) == 3:
var1 = item[0]
var2 = item[1]
var3 = item[2]
if len(item) == 4:
var1 = item[0]
var2 = item[1]
var3 = item[2]
var4 = item[3]
fun(var1,var2,var3,var4,var5,var6)
I have a function
def fun(var1, var2 = None, var3 = None, var4 = None, var5=None, var6= None)
Depending upon the values in my inner list. I am passing it to function.
I hope I made it clear.
Thanks