Tag:black hole

  • Python anonymous function (lambda)


    Compared with normal writing, using anonymous functions is quite concise Map () traverses all a = [1, 2, 3] x = [] for each in a: x.append(each+1) print(x) ###Using map (func, Iterable) print(list(map(lambda x: x+1, a))) Reduce (func, SEQ) accumulates the value of each calculation def num(x, y): return x + y print(reduce(num, [1, 2, […]

  • Python coroutine


      Before the coroutine, we understand the process and thread of Python. Here, let’s talk about the coroutine Instead, the subroutine switches itself There is no overhead of thread switching. Compared with multithreading, the more threads there are, the more obvious the performance advantage of coprocessor There is no need for multi-threaded locking mechanism, because […]

  • python copy


    Python copy is divided into deep copy and shallow copy The shallow copy does not copy the sub object, the deep copy copies all l1 = [1, 2, [3, 4]] l2 = copy.copy(l1) l1.append(5) L1 [2]. Append (5) sub object change print(l1) print(l2) ————– [1, 2, [3, 4, 5], 5] [1, 2, [3, 4, 5]] […]