Jed Rembold
November 12, 2024
What is the printed value of the below code?
A = [
{'name': 'Jill', 'weight':125, 'height':62},
{'name': 'Sam', 'height':68},
{'name': 'Bobby', 'height':72},
]
A.append({'weight':204, 'height':70, 'name':'Jim'})
B = A[1]
B['weight'] = 167
A.append(B)
print([d['weight'] for d in A if 'weight' in d])
[125,70,167]
[125,167,204,167]
[125,204,167]
Year | Registration Date | Registration Day |
---|---|---|
4 | 11/18 | Monday |
3 | 11/19 | Tuesday |
2 | 11/21 | Thursday |
1 | 11/25 | Following Monday |
If [Caesar] had anything confidential to say, he wrote it in cipher, that is, by so changing the order of the letters of the alphabet, that not a word could be made out.
Enclosed within squiggly brackets
No key-value pairs, just single values separated by commas
digits = { 0, 1, 2, 3, 4, 6, 7, 8, 9 }
squares = { 0, 1, 4, 9 }
primary = { "red", "green", "blue" }
Set elements must be immutable
Sets themselves are generally mutable
Can not create an empty set just using
{ }
!
set()
.3 in primes
A.union(B)
A | B
A.intersection(B)
A & B
A.difference(B)
A - B
A.symmetric_difference(B)
A ^ B
If we have the following sets from earlier:
digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } |
evens = { 0, 2, 4, 6, 8 } |
odds = { 1, 3, 5, 7, 9 } |
primes = { 2, 3, 5, 7 } |
squares = { 0, 1, 4, 9 } |
What is the value of each of the following: