Python - zip only lists that contain data -
i have script converts data 1 type another. source file can have one, 2 or of: position, rotation , scale data.
my script zips 3 after conversions have taken place output file.
in case, source file contains position data. lists returned @ end are:
pdata = [['-300.2', '600.5'],['150.12', '280.7'],['19.19', '286.56']] rdata = [] sdata = [] translationdata = list(zip(pdata, rdata, sdata))
if try this, return []
because shortest list []
. if try:
translationdata = list(zip_longest(pdata, rdata, sdata))
i get:
`[(['-300.2', '600.5'], none, none), (['150.12', '280.7'], none, none), (['19.19', '286.56'], none, none)]`
is there way zip lists contain data, or remove none
's within tuples within list?
thanks in advance!
you can use filter
builtin embedded in list-comp.
note: in python 3
filter
returns iterator, need calltuple()
on it. (unlike in py2)
pdata = [['-300.2', '600.5'],['150.12', '280.7'],['19.19', '286.56']] rdata = [] sdata = [] itertools import zip_longest # izip_longest python 2 [tuple(filter(none, col)) col in zip_longest(pdata, rdata, sdata)]
result:
[(['-300.2', '600.5'],), (['150.12', '280.7'],), (['19.19', '286.56'],)]
Comments
Post a Comment