Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 10, 2020 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/86ca687258ea86abbc8ba9437a003355 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/86ca687258ea86abbc8ba9437a003355 to your computer and use it in GitHub Desktop.
#creating dictionary by using iterables
d=dict([('red',1),('blue',2),('green',3)])
print (d)#Output:{'red': 1, 'blue': 2, 'green': 3}
#creating dictionary using iterables and keyword arguments
d=dict([('red',1),('blue',2)],green=3)
print (d)#Output:{'red': 1, 'blue': 2, 'green': 3}
#creating dictionary by using zip().zip() also creates iterbales
d=dict(zip(['red','green','blue'],[1,2,3]))
print (d)#Output:{'red': 1, 'green': 2, 'blue': 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment