Skip to content

Instantly share code, notes, and snippets.

@marksagal
Created October 19, 2017 21:38
Show Gist options
  • Save marksagal/82e6686812118855ec11017d18e6ecbd to your computer and use it in GitHub Desktop.
Save marksagal/82e6686812118855ec11017d18e6ecbd to your computer and use it in GitHub Desktop.
# A. Current Data - Poorly structured
contact_emails = {
'brian': '[email protected]',
'ted': '[email protected]',
'donald': '[email protected]'
}
# A. Loop
for name in contact_emails:
email = contact_emails[name]
print(name, email)
# B. Dicts wrapped in List
contact_emails = [
{'name': 'brian', 'email': '[email protected]'},
{'name': 'ted', 'email': '[email protected]'},
{'name': 'donald', 'email': '[email protected]'}
]
# B. Loop
for info in contact_emails:
print(info['name'], info['email'])
# C. Tuples wrapped in List
contact_emails = [
('biran', '[email protected]'),
('ted', '[email protected]'),
('donald', '[email protected]')
]
# C. Loop
for name, email in contact_emails:
print(name, email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment