Skip to content

Instantly share code, notes, and snippets.

@jorge-lavin
Last active August 29, 2015 14:16
Show Gist options
  • Save jorge-lavin/24abaaed52b05e126551 to your computer and use it in GitHub Desktop.
Save jorge-lavin/24abaaed52b05e126551 to your computer and use it in GitHub Desktop.
Combine two lists with a default value
def list_zipper(list_1, list_2):
for (x_1, x_2) in zip(list_1, list_2):
if not x_1:
yield '{x_2}_vacio'.format(x_2=x_2)
else:
yield x_1
if __name__ == '__main__':
list_1 = ['aaa', '', 'ccc']
list_2 = ['titulo_1', 'titulo_2', 'titulo_3']
print(list(list_zipper(list_1, list_2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment