File tree Expand file tree Collapse file tree 9 files changed +252
-16
lines changed
Expand file tree Collapse file tree 9 files changed +252
-16
lines changed Original file line number Diff line number Diff line change 11.idea
2+ test
Original file line number Diff line number Diff line change 1+ # -*- encoding: utf-8 -*-
2+ """
3+ PyCharm show
4+ 2022年06月17日
5+ by littlefean
6+ """
7+ from typing import *
8+
9+
10+ # ... 可以写在注解里面
11+ def test (a : ..., b : ...) -> ...:
12+ ...
13+
14+
15+ # 有一个类我还不知道怎么写,我可以先写个占位符
16+ class A :
17+ ...
18+
19+
20+ class B :
21+ pass
22+
23+
24+ def f ():
25+ ...
26+
27+
28+ def g ():
29+ pass
30+
31+
32+ def main ():
33+ # 写个空循环
34+ for _ in range (10 ):
35+ ...
36+
37+ # 经过测试发现 点点点和pass做空循环速度是一样的。
38+
39+ for _ in range (100 ):
40+ ...
41+ ...
42+ ...
43+ ...
44+
45+ # 经过测试发现,这样写四个,并没有出现速度慢了四倍的情况
46+
47+ print (id (...) == id (Ellipsis ))
48+ # print(id(...) == id(ellipsis)) # 没有小写开头的东西了,因为是单例了,虽然pycharm里这个单词还会变蓝
49+ return None
50+
51+
52+ if __name__ == "__main__" :
53+ main ()
Original file line number Diff line number Diff line change 1+ # -*- encoding: utf-8 -*-
2+ """
3+ PyCharm show
4+ 2022年06月17日
5+ by littlefean
6+ """
7+ from typing import *
8+
9+ # 先引入
10+ from functools import lru_cache
11+
12+
13+ # 装饰你要递归的函数
14+ @lru_cache (None )
15+ def fab (n ):
16+ if n == 1 :
17+ return 1
18+ if n == 2 :
19+ return 1
20+ return fab (n - 1 ) + fab (n - 2 )
21+
22+
23+ def main ():
24+ for i in range (1 , 101 ):
25+ print (i , fab (i ))
26+ """
27+ 注意点:
28+ 装饰的函数的每一个参数都是要可哈希的,
29+ int、float、str都可以,但是传了一个list不可以。
30+ """
31+ return None
32+
33+
34+ if __name__ == "__main__" :
35+ main ()
Original file line number Diff line number Diff line change 1+ # -*- encoding: utf-8 -*-
2+ """
3+ PyCharm show
4+ 2022年06月17日
5+ by littlefean
6+ """
7+ from typing import *
8+
9+
10+ def main ():
11+ left = 1
12+ right = 1000
13+ mid = (left + right ) >> 1
14+ print (mid )
15+ # 比如说求中点位置,就可以用位运算,相当于除以二
16+ return None
17+
18+
19+ if __name__ == "__main__" :
20+ main ()
Original file line number Diff line number Diff line change 1+ # -*- encoding: utf-8 -*-
2+ """
3+ PyCharm test
4+ 2022年06月12日
5+ by littlefean
6+ """
7+ from typing import *
8+ import threading
9+
10+
11+ def f ():
12+ for i in range (100000 ):
13+ print ("\t " , i )
14+ ...
15+
16+
17+ def g ():
18+ for i in range (100000 ):
19+ print (i )
20+ ...
21+
22+
23+ def main ():
24+ # t1 = threading.Thread(target=f)
25+ # t2 = threading.Thread(target=g)
26+ # t1.start()
27+ # t2.start()
28+
29+ return None
30+
31+
32+ if __name__ == "__main__" :
33+ main ()
Original file line number Diff line number Diff line change 1+ import decimal
2+ from typing import *
3+
4+ from decimal import *
5+
6+
7+ def main ():
8+ decimal .getcontext ().prec = 20
9+ N = 100
10+ for i in range (1 , N - 1 ):
11+ for j in range (i + 1 , N ):
12+ f = Decimal (i ) / Decimal (j )
13+ print (f"{ i } /{ j } " , f )
14+
15+ return None
16+
17+
18+ if __name__ == "__main__" :
19+ main ()
Original file line number Diff line number Diff line change 1+ import fractions
2+ import decimal
3+
4+
5+ a = fractions .Fraction (1 , 5 )
6+ print (a )
7+ a += 5
8+ print (a )
9+
10+ print (a .numerator )
11+ print (a .denominator )
12+
13+ # a3 = fractions.Fraction(1, 3)
14+ a3 = fractions .Fraction (1 , 7 )
15+ print (a3 )
16+ print (float (a3 ))
17+ print (decimal .Decimal (1 ) / decimal .Decimal (3 ))
18+
19+
20+
Original file line number Diff line number Diff line change 1- def f (item ):
2- del item
3- return f
1+ # def f(item):
2+ # del item
3+ # return f
4+ #
5+ #
6+ # f(f)(f)
47
8+ # error
9+ def g (a ):
10+ del g
11+ return a
512
6- f (f )(f )
713
8- # error
9- # def g(a):
10- # del g
11- # return a
12- #
13- #
1414# g(g)(g)
1515
16- a = [1 , 2 , 3 ]
17- f (a )
18- print (a ) # 无影响
19-
20- obj = object ()
21- help (obj )
16+ # a = [1, 2, 3]
17+ # f(a)
18+ # print(a) # 无影响
19+ #
20+ # obj = object()
21+ # help(obj)
Original file line number Diff line number Diff line change 1+ from array import array
2+ from time import perf_counter
3+ from random import randint
4+
5+ # print(lst)
6+ # print(arr)
7+
8+ # 测试随机修改
9+ N = 1000000
10+
11+
12+ def test1 ():
13+ lst = list (range (100 ))
14+ arr = array ("i" , lst )
15+ t1 = perf_counter ()
16+
17+ for _ in range (N ):
18+ lst [randint (0 , len (lst ) - 1 )] = 666
19+
20+ t2 = perf_counter ()
21+
22+ for _ in range (N ):
23+ arr [randint (0 , len (arr ) - 1 )] = 666
24+
25+ t3 = perf_counter ()
26+ print (t2 - t1 , t3 - t2 )
27+
28+
29+ def test2 ():
30+ """
31+ append
32+ """
33+ arr1 = array ("i" )
34+
35+ t1 = perf_counter ()
36+ lst1 = [1 for _ in range (N )]
37+ t2 = perf_counter ()
38+ for _ in range (N ):
39+ arr1 .append (1 )
40+ t3 = perf_counter ()
41+ print (lst1 .__sizeof__ ())
42+ print (arr1 .__sizeof__ ())
43+ print (t2 - t1 , t3 - t2 )
44+
45+
46+ def test3 ():
47+ t1 = perf_counter ()
48+ arr = array ("i" , range (N ))
49+ t2 = perf_counter ()
50+ lst = list (range (N ))
51+ t3 = perf_counter ()
52+ print (t2 - t1 , t3 - t2 )
53+
54+
55+ test3 ()
You can’t perform that action at this time.
0 commit comments