python - Conditional zip of two lists -


i'm trying zip 2 lists create new dictionary. list 1 list of column names represented string, while list 2 list of variables.

if variable empty (none) don't want or corresponding column data (they share same index, 'foo' column @ index 0 , 'foo' variable) within dict.

i've tried few ways construct using dict comprehension haven't been able create it.

my dict needs ordered i'm using ordereddict module well.

is possible this?

edit:

here's how data should look.

list_1 = ['foo', 'bar', 'baz', 'whatever'] list_2 = [foo, bar, baz, whatever] 

now lets imagine whatever variable none.

the dict, create should like

d = {  'foo' : foo, 'bar' : bar, 'baz' : baz } 

as martijn points out in comments, want ordereddict((k, v) k, v in zip(list_1, list_2) if v not none).


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -