Last active
August 29, 2015 14:16
-
-
Save jorge-lavin/24abaaed52b05e126551 to your computer and use it in GitHub Desktop.
Combine two lists with a default value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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