Skip to content

Instantly share code, notes, and snippets.

@marksagal
Created October 19, 2017 21:38
Show Gist options
  • Select an option

  • Save marksagal/82e6686812118855ec11017d18e6ecbd to your computer and use it in GitHub Desktop.

Select an option

Save marksagal/82e6686812118855ec11017d18e6ecbd to your computer and use it in GitHub Desktop.
# A. Current Data - Poorly structured
contact_emails = {
'brian': 'brian@google.com',
'ted': 'ted@google.com',
'donald': 'donald@google.com'
}
# A. Loop
for name in contact_emails:
email = contact_emails[name]
print(name, email)
# B. Dicts wrapped in List
contact_emails = [
{'name': 'brian', 'email': 'brian@google.com'},
{'name': 'ted', 'email': 'ted@google.com'},
{'name': 'donald', 'email': 'donald@google.com'}
]
# B. Loop
for info in contact_emails:
print(info['name'], info['email'])
# C. Tuples wrapped in List
contact_emails = [
('biran', 'brian@google.com'),
('ted', 'ted@google.com'),
('donald', 'donald@google.com')
]
# 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