You are on page 1of 5

Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.

1900 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.

>>> d = {}

>>> d["tot"] = 2

>>> d

{'tot': 2}

>>> d["pop"] = 60

>>> d

{'tot': 2, 'pop': 60}

>>> d1 = dict({"id": 1948, "name": "Washer", "size": 3})

>>> d2 = dict(id = 1948, name = "Washer", size = 3)

>>> d3 = dict([("id", 1948), ("name", "Washer"), ("size", 3)])

>>> d4 = dict(zip(("id", "name", "size"), (1948, "Washer", 3)))

>>> d5 = {"id": 1948, "name": "Washer", "size":3}

>>> dic = {[1,2,3]:"abc"}

Traceback (most recent call last):

File "<pyshell#10>", line 1, in <module>

dic = {[1,2,3]:"abc"}

TypeError: unhashable type: 'list'

>>> dic = {(1,2,3): "abc", 3.1415: "abc"}

>>> dic

{3.1415: 'abc', (1, 2, 3): 'abc'}

>>> words = {"house":"home", "cat":"meow"}

>>> words["car"]

Traceback (most recent call last):

File "<pyshell#14>", line 1, in <module>

words["car"]

KeyError: 'car'

>>> if "car" in words: print words["car"]


SyntaxError: Missing parentheses in call to 'print'

>>> if "cat" in words: print words["cat"]

SyntaxError: Missing parentheses in call to 'print'

>>> if "cat" in words: print words(["cat"])

SyntaxError: invalid syntax

>>> if "cat" in words:

print(words["cat"])

meow

>>> w = words.copy()

>>> words["cat"] = "chat"

>>> print w

SyntaxError: Missing parentheses in call to 'print'

>>> print(w)

{'house': 'home', 'cat': 'meow'}

>>> print(words)

{'house': 'home', 'cat': 'chat'}

>>> w.clear()

>>> print(w)

{}

>>> dic = {(1,2,3): "abc", 3.1415: "abc"}

>>> words = {"house":"home", "cat":"meow"]

SyntaxError: invalid syntax

>>> words = {"house":"home", "cat":"meow"}

>>> w1.update(dic)

Traceback (most recent call last):

File "<pyshell#31>", line 1, in <module>

w1.update(dic)
NameError: name 'w1' is not defined

>>> words.update(dic)

>>> words

{'house': 'home', (1, 2, 3): 'abc', 3.1415: 'abc', 'cat': 'meow'}

>>> words = {"house":"home", "Cat":"meow"}

>>> list(words.items())

[('house', 'home'), ('Cat', 'meow')]

>>> list(words.keys())

['house', 'Cat']

>>> list(words.values())

['home', 'meow']

>>> dishes = ["pizza", "sauerkraut", "paella", "Hamburger"]

>>> countries = ["Italy", "Germany", "Spain", "USA"]

>>> country_specialities = list(zip(countries, dishes))

>>> country_ speacialities

SyntaxError: invalid syntax

>>> country_specialities

[('Italy', 'pizza'), ('Germany', 'sauerkraut'), ('Spain', 'paella'), ('USA', 'Hamburger')]

>>> country_specialities_dict = dict(country_specialities)

>>> country_specialities_dict

{'Spain': 'paella', 'Italy': 'pizza', 'USA': 'Hamburger', 'Germany': 'sauerkraut'}

>>> countries = ["Italy", "Germany", "Spain", "USA", "Switzerland"]

>>> dishes = ["pizza", "sauerkraut", "paella", "Hamburger"]

>>> country_specialities = list(zip(countries, dishes))

>>> country_specialities

[('Italy', 'pizza'), ('Germany', 'sauerkraut'), ('Spain', 'paella'), ('USA', 'Hamburger')]

>>> app = {2017: {'February':{1:{'11am':'lab'}}}}

>>> app = {}

>>> app[2017] = 'February'


>>> app

{2017: 'February'}

>>> app[2017] = {}

>>> app

{2017: {}}

>>> app[2017]['February'] = 15

>>> app

{2017: {'February': 15}}

>>> app[2017]['February'] = {}

>>> app

{2017: {'February': {}}}

>>> app[2017]['February'][15] = '11am'

>>> app

{2017: {'February': {15: '11am'}}}

>>> app[2017]['February'] = {}

>>> app

{2017: {'February': {}}}

>>> app[2017]['February'][15] = {}

>>> app

{2017: {'February': {15: {}}}}

>>> app[2017]['February'][15]['11am'] = 'lab'

>>> app

{2017: {'February': {15: {'11am': 'lab'}}}}

>>> app[2017]['February'][15]['12pm'] = 'TA office hours'

>>> app

{2017: {'February': {15: {'12pm': 'TA office hours', '11am': 'lab'}}}}

>>> app[2017]['February'][16] = {}

>>> app

{2017: {'February': {16: {}, 15: {'12pm': 'TA office hours', '11am': 'lab'}}}}
>>> app[2017]['February'][16]['12pm'] = 'cs1004 class'

>>> app

{2017: {'February': {16: {'12pm': 'cs1004 class'}, 15: {'12pm': 'TA office hours', '11am': 'lab'}}}}

>>> app[2017]['March'] = {}

>>> app

{2017: {'February': {16: {'12pm': 'cs1004 class'}, 15: {'12pm': 'TA office hours', '11am': 'lab'}}, 'March': {}}}

>>> app[2017]['March'][2] = {}

>>> app[2017]['March

SyntaxError: EOL while scanning string literal

>>>

KeyboardInterrupt

>>> app[2017]['March'][2]['12pm'] = 'cs1004 final quiz'

>>> app

{2017: {'February': {16: {'12pm': 'cs1004 class'}, 15: {'12pm': 'TA office hours', '11am': 'lab'}}, 'March': {2:
{'12pm': 'cs1004 final quiz'}}}}

>>> app[2017]['February'][15]

{'12pm': 'TA office hours', '11am': 'lab'}

>>>

You might also like