python - Make a list of dicts by iterating over two lists (list comprehensions) -


the lists have same number of elements, , names unique. wonder, how can make dict in 1 action.

this current code:

    fees = [fee fee in fees]     names = [name name in names]     mdict = [         {'fees': fee[i], 'names': names[i]}         i, val in enumerate(fees)] 

you can use zip on both lists in list comprehension:

mdict = [{'fees': f, 'names': n} f, n in zip(fees, names)] 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -