python
文章平均质量分 65
烨渔
这个作者很懒,什么都没留下…
展开
-
CS61A Fall 2021 discussion 6——q5-q7
Q5: MergeWrite a generator function merge that takes in two infinite generators a and b that are in increasing order without duplicates and returns a generator that has all the elements of both generators, in increasing order, without duplicates.def merg原创 2022-02-07 16:19:50 · 791 阅读 · 0 评论 -
CS61a 2021Fall discussion 5——additional practice
CS61a 2021Fall discussion 5 additional practiceQ7: Perfectly BalancedQ8: Hailstone TreeQ7: Perfectly BalancedPart A: Implement sum_tree, which returns the sum of all the labels in tree t.Part B: Implement balanced, which returns whether every branch of原创 2022-01-25 17:52:07 · 414 阅读 · 0 评论 -
python str()函数在处理浮点数时的一个特性
python str()函数在处理浮点数时的一个特性起因是在做正则匹配匹配浮点数的时候发现有一些数据无法匹配成功:rec = re.compile(r'^[1-9]\d*\.\d*|0\.\d*[1-9]$')s = [0.0001, 0.00001, 0.12165, 0.000, 0.0000, 1.00000000][i for i in s if rec.match(str(i))] # 输出:[0.0001, 0.12165, 1.0]1e−41e-41e−4还能匹配成功,但是1e−原创 2021-11-15 10:55:23 · 1641 阅读 · 0 评论