Skip to content Skip to sidebar Skip to footer

The Smart Way To Recombine These Two Lists In Python

i have the following lists in python which i want to recombine into a dictionary/list: names = ['banana','grapefruit','apple'] colors = ['yellow','pink','green'] to fruits = [ {'n

Solution 1:

fruits = [{"name": name, "color": color} for name, color in zip(names, colors)]

Post a Comment for "The Smart Way To Recombine These Two Lists In Python"