Median output rate: 34.06 chars / s
Prompt | Answer | Latency |
---|---|---|
Write a Python function to find the nth number in the Fibonacci Sequence. | def fibonacci(n): if n == 0: return 0 elif n == 1: return 1 else: return fibonacci(n-1) + fibonacci(n-2) print(fibonacci(10)) # | 3780ms |
Write a Python function that prints the next 20 leap years. Reply with only the function. | # | 504ms |
Explain the bug in the following code: ``` from time import sleep from multiprocessing.pool import ThreadPool def task(): sleep(1) return 'all done' if __name__ == '__main__': with ThreadPool() as pool: result = pool.apply_async(task()) value = result.get() print(value) ``` | """ """ ## `multiprocessing.pool.ThreadPool` """ """ ### `ThreadPool` """ """ #### `ThreadPool.apply_async()` """ """ #### `ThreadPool.close()` """ """ #### `ThreadPool.join()` """ """ #### `ThreadPool.map()` """ """ #### `ThreadPool.starmap()` """ """ #### `ThreadPool.terminate()` """ """ #### `ThreadPool.close()` """ """ #### `ThreadPool.join()` """ """ #### `ThreadPool.map()` """ """ #### `ThreadPool.starmap()` """ """ #### `ThreadPool.terminate()` """ """ #### `ThreadPool.close()` """ """ #### `ThreadPool.join()` """ | 16401ms |
Explain simply what this function does: ``` def func(lst): if len(lst) == 0: return [] if len(lst) == 1: return [lst] l = [] for i in range(len(lst)): x = lst[i] remLst = lst[:i] + lst[i+1:] for p in func(remLst): l.append([x] + p) return l ``` | """ def func(lst): if len(lst) == 0: return [] if len(lst) == 1: return [lst] l = [] for i in range(len(lst)): x = lst[i] remLst = lst[:i] + lst[i+1:] for p in func(remLst): l.append([x] + p) return l func([1, 2, 3]) """ ## Exercise Write a function that takes a list of numbers and returns a list of lists of numbers. For example: ``` func([1, 2, 3]) ``` should return: ``` [[1], [2], [3]] ``` """ def func(lst): if len(lst) == 0: return [] if len(lst) == 1: return [lst] l = [] | 17301ms |