Solução do Exercício + zip e zip_longest do itertools
This commit is contained in:
10
aula107.py
10
aula107.py
@@ -8,3 +8,13 @@
|
||||
# ['BA', 'SP', 'MG', 'RJ']
|
||||
# Resultado
|
||||
# [('Salvador', 'BA'), ('Ubatuba', 'SP'), ('Belo Horizonte', 'MG')]
|
||||
|
||||
# def zipper(l1, l2):
|
||||
# intervalo = min(len(l1), len(l2))
|
||||
# return [(l1[i], l2[i]) for i in range(intervalo)]
|
||||
from itertools import zip_longest
|
||||
|
||||
l1 = ['Salvador', 'Ubatuba', 'Belo Horizonte']
|
||||
l2 = ['BA', 'SP', 'MG', 'RJ']
|
||||
print(list(zip(l1, l2)))
|
||||
print(list(zip_longest(l1, l2, fillvalue='SEM CIDADE')))
|
||||
|
||||
Reference in New Issue
Block a user