better way of handling nested list
Posted
by
laspal
on Stack Overflow
See other posts from Stack Overflow
or by laspal
Published on 2010-12-21T06:14:43Z
Indexed on
2010/12/21
6:54 UTC
Read the original article
Hit count: 244
python
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
© Stack Overflow or respective owner