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 call tuple() 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -