Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: Dictionaries

📅 2009-Oct-12 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ dictionaries, python ⬩ 📚 Archive

Create empty dictionary

adict={}

# Create dictionary with key-value pairs
adict={10:"foobar", 99:"hello world"}   # {10: 'foobar', 99: 'hello world'}

# Add new key-value pair to dictionary
adict[30]=1234567                       # {10: 'foobar', 99: 'hello world', 30: 1234567}

# Delete element from dictionary
del adict[10]                           # {99: 'hello world', 30: 1234567}

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧