Skip to content

Instantly share code, notes, and snippets.

@GTimothee
Created June 14, 2018 13:45
Show Gist options
  • Save GTimothee/0fe7f065c8e4eb2d611bee85aefe8ed2 to your computer and use it in GitHub Desktop.
Save GTimothee/0fe7f065c8e4eb2d611bee85aefe8ed2 to your computer and use it in GitHub Desktop.
https://www.digitalocean.com/community/tutorials/how-to-handle-plain-text-files-in-python-3
#from list of tuples
class Person(object):
def __init__(self, name, profession):
self.name = name
self.profession = profession
people = [Person("Nick", "Programmer"), Person("Alice","Engineer")]
professions = dict([ (p.name, p.profession) for p in people ])
#from two lists
names = ["Nick", "Alice", "Kitty"]
professions = ["Programmer", "Engineer", "Art Therapist"]
names_and_professions = zip(names, professions)
'''
print zip(range(5), ["a","b","c","d","e"])
[(0, "a"), (1, "b"), (2, "c"), (3, "d"), (4, "e")]
'''
professions_dict = dict(zip(names, professions))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment