CS61A Lecture 11 && 12Data Abstraction && Tree

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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值