python - Iteration in one line of code -


i noob in python , think have relevant question.

i have 2 lists in python :

in lista have column names of mysql table.

lista = ["columna","columnb","columnc"] 

in listb have result of query values

listb = [["10","30","40"],          ["14","28","38"],          ["13","23","45"]] 

what efficient way in python produce output this?

   columna = 10, columnb = 30, columnc = 40    columna = 14, columnb = 28, columnc = 38    columna = 13, columnb = 23, columnc = 45 

a list of dictionaries work well:

>>> [dict(zip(lista, row)) row in listb] [{'columna': '10', 'columnc': '40', 'columnb': '30'}, {'columna': '14', 'columnc': '38', 'columnb': '28'}, {'columna': '13', 'columnc': '45', 'columnb': '23'}] >>>  

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -