Lecture 11 Data Abstraction
1.rational numbers(有理数)
2.pairs
3.abstraction barriers
4.conductors and selectors
5.data representations
6.dictionary
>>>numerals = {'I': 1, 'V': 5, 'X': 10}
>>>numerals
{'X': 10, 'V': 5, 'I': 1}
>>>numerals['X']
10
>>>numerals[10]
Traceback (most recent call last):
File"<stdin?", line 1, in <module>
KeyError: 10
>>>numerals.keys()
dict_keys(['X', 'V', 'I'])
>>>numerals.vlaues()
dict_values([10, 5, 1])
>>>numerals.items()
dict_items([('X',10), (;V;, 5), ('I', 1)])
>>>'X' in numerals
True
>>>numerals.get('X', 0)
10
>>>numerals.get('X-ray', 0)
0
>>>squares = {x:x*x for x in range(10)}
>>>squares[7]
49
>>>{1: 2, 1: 3}
{1:3} //不能一个key对应两个值
Lecture 12 Tree
1.Box-and-Pointer Notation
2.slicing
>>>odds = [1, 3, 5, 7]
>>>satrt = odds[:3]
>>>start
[1, 3]
3.processing continers
>>>sum[[2, 3, 5], 1]
11
>>>max(range(5))
4
/key(function in max) return the number make the key max
>>>max(range(10), key=lambda x: 7-(x-4)*(x-2))
3
//bool function
all(iterable)->bool
4.Tree