create dictionary in python using two sets -



create dictionary in python using two sets -

i have merge 2 sets:

colors={'green','yellow','purple','blue','red'}

and

children={'uri','ron','sigalit','ruti','alon'}

into single dictionary using children keys. i'm not allowed utilize loops, , not allowed utilize indexing. clues how this?

you can utilize dict comprehension.

children = {'uri','ron','sigalit','ruti','alon'} colors = {'green','yellow','purple','blue','red'} >>> {x:y x,y in zip(children,colors)} {'uri': 'green', 'ruti': 'blue', 'ron': 'yellow', 'alon': 'red', 'sigalit': 'purple'}

python python-2.7 set

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -