-
-
Save IndhumathyChelliah/6f8e4380eb1a59da3157b568114c615c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l1=[1,'a',2,'b',3,'c',4,'d'] | |
#Creating list containing keys alone by slicing | |
l2=l1[::2] | |
#Creating list containing values alone by slicing | |
l3=l1[1::2] | |
#merging two lists uisng zip() | |
z=zip(l2,l3) | |
#Converting zip object to dict using dict() constructor. | |
print (dict(z)) | |
#Output:{1: 'a', 2: 'b', 3: 'c', 4: 'd'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment