How do I create a dictionary with multiple values eg? a list or tuple, for each key?

2

I have 2 lists

lista_nom = [['Luisa Cordoba'], ['Olga Leiva'], ['Graciela Sanchez']]

lista_mate = [['CIENCIAS', 7.2, 'MATEMATICAS', 9.0, 'ALGEBRA', 6.5, 'FISICA', 2.1, 'QUIMICA', 1.7], ['CIENCIAS', 4.5, 'MATEMATICAS', 9.8, 'ALGEBRA', 5.7, 'FISICA', 8.2, 'QUIMICA', 9.1], ['CIENCIAS', 7.0, 'MATEMATICAS', 3.3, 'ALGEBRA', 5.7, 'FISICA', 6.7, 'QUIMICA', 9.0]]

Manually iterating on lista_nom[x] and lista_mate[x:10] the next line creates me an entry of the desired dictionary but how do I go adding each entry in the dictionary?

diccio_fin = dict(zip(lista_nom[0], lista_mate[0:10]))

{'Luisa Cordoba': ['CIENCIAS', 7.2, 'MATEMATICAS', 9.0, 'ALGEBRA', 6.5, 'FISICA', 2.1, 'QUIMICA', 1.7]}

diccio_fin = dict(zip(lista_nom[1], lista_mate[1:10]))

{'Olga Leiva': ['CIENCIAS', 4.5, 'MATEMATICAS', 9.8, 'ALGEBRA', 5.7, 'FISICA', 8.2, 'QUIMICA', 9.1]}

diccio_fin = dict(zip(lista_nom[2], lista_mate[2:10]))

{'Graciela Sanchez': ['CIENCIAS', 7.0, 'MATEMATICAS', 3.3, 'ALGEBRA', 5.7,
  'FISICA', 6.7, 'QUIMICA', 9.0]}
    
asked by Ignacio Fabregas 03.05.2018 в 02:19
source

1 answer

0

I think what you're looking for is this:

diccio_fin = dict((e[0][0],e[1]) for e in zip(lista_nom, lista_mate))
print(diccio_fin)

{'Luisa Cordoba': ['CIENCIAS', 7.2, 'MATEMATICAS', 9.0, 'ALGEBRA', 6.5, 'FISICA', 2.1, 'QUIMICA', 1.7], 'Olga Leiva': ['CIENCIAS', 4.5, 'MATEMATICAS', 9.8, 'ALGEBRA', 5.7, 'FISICA', 8.2, 'QUIMICA', 9.1], 'Graciela Sanchez': ['CIENCIAS', 7.0, 'MATEMATICAS', 3.3, 'ALGEBRA', 5.7, 'FISICA', 6.7, 'QUIMICA', 9.0]}
  • We combine each element of both list in a tuple with zip(lista_nom, lista_mate)
  • We go through each case with an "understanding of lists e[0][0] will be the key and e[1] the value
answered by 03.05.2018 / 04:37
source