In [7]:
a = {'one':1, 'two':2, 'three': 3}
b = dict(one=1, two=2, three= 3)
c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
a == b == c
Out[7]:
In [8]:
a['one']
Out[8]:
In [11]:
a['two'] = 'dos'
a
Out[11]:
In [12]:
a['four'] = 4
a
Out[12]:
In [13]:
del a['one']
a
Out[13]:
In [16]:
for k in a.keys():
print(k)
for k in a:
print(k)
In [19]:
for k in a:
print(a[k])
print()
for val in a.values():
print(val)
print()
for k, val in a.items():
print(val)
In [23]:
for k, val in a.items():
print((k, val))
print()
for k in a:
print((k, a[k]))
print()
for elem in a.items():
print(elem)
In [36]:
# Aliasing
a = {}
b = a
b['hi'] = 1
b
# Copy
a = {}
b = a.copy()
b['hi'] = 1
b
# Aliasing
a = []
b = a
b.append(1)
b
# copy
a = []
b = a[:]
b.append(1)
a
# copy
a = []
b = a.copy()
b.append(1)
a
# Immutable datastructures (ex. tuples) can't be updated so no way to alias.
a = ()
b = a
b = b + (1,)
a
Out[36]:
Pair up with another group and review each others code.
35 points possible 15: Program runs and consistently produces correct output.
5 point penalty for any of the following:
- Test cases running in addition to program functionality. (You need to 'comment out' any 'test' print statements for your final testing and turn-in.)
- Incorrect or missing counts of emails or dates.
- Other extra output, missing output, or output formatted differently than the examples above.
- 10: Follows PEP8 coding guidelines, including author identification and header.
- 10: Clarity. The program should not only be consistent with the requirements and approach described here, but it should be very easy to read the program and verify its consistency with the spec.
In [ ]: