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
Post a Comment