Tag:black hole

  • Python anonymous function (lambda)

    Time:2020-11-12

    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

    Time:2020-9-16

      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

    Time:2020-6-19

    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]] […]