What is the difference between `copy.copy()` and `copy.deepcopy()` for a list containing mutable objects? Python DeveloperHard Try Now
What is the output of the following? “`python from itertools import groupby data = [(‘a’,1),(‘a’,2),(‘b’,3),(‘b’,4),(‘a’,5)] result = {k: list(v) for k, v in groupby(data, key=lambda x: x[0])} print(result) “` Python DeveloperHard Try Now
What is Python’s `asyncio` event loop and how does `await` affect coroutine execution? Python DeveloperHard Try Now
What is the output of the following? “`python data = [3, 1, 4, 1, 5, 9, 2, 6] result = sorted(data, key=lambda x: -x) print(result[:3]) “` Python DeveloperHard Try Now
What does `contextlib.contextmanager` allow and how does `yield` work inside it? Python DeveloperHard Try Now
What is the output of the following? “`python class A: def method(self): return ‘A’ class B(A): def method(self): return super().method() + ‘B’ class C(A): def method(self): return super().method() + ‘C’ class D(B, C): pass print(D().method()) “` Python DeveloperHard Try Now
What is the output of the following? “`python import threading results = [] lock = threading.Lock() def worker(n): with lock: results.append(n * 2) threads = [threading.Thread(target=worker, args=(i,)) for i in range(3)] for t in threads: t.start() for t in threads: t.join() print(sorted(results)) “` Python DeveloperHard Try Now
What is the output of the following? “`python from collections import defaultdict d = defaultdict(list) d[‘a’].append(1) d[‘a’].append(2) d[‘b’].append(3) print(dict(d)) “` Python DeveloperHard Try Now
What is a Python descriptor and what three methods define the descriptor protocol? Python DeveloperHard Try Now
What is the output of the following? “`python def counter(start=0): count = start def increment(): nonlocal count count += 1 return count return increment c = counter(10) print(c()) print(c()) “` Python DeveloperHard Try Now
What does `itertools.chain(*iterables)` do and how is it more efficient than concatenation? Python DeveloperHard Try Now
What is the output of the following? “`python class Meta(type): def __new__(mcs, name, bases, ns): ns[‘greeting’] = lambda self: f’Hello from {name}’ return super().__new__(mcs, name, bases, ns) class MyClass(metaclass=Meta): pass obj = MyClass() print(obj.greeting()) “` Python DeveloperHard Try Now
What is a Python context manager and what dunder methods must a class implement to support `with`? Python DeveloperHard Try Now
What is the output of the following? “`python from functools import reduce result = reduce(lambda acc, x: acc + x, [1, 2, 3, 4, 5]) print(result) “` Python DeveloperHard Try Now
What is the difference between `__str__` and `__repr__` in Python classes? Python DeveloperHard Try Now
What is the output of the following? “`python gen = (x * 2 for x in range(4)) print(next(gen)) print(next(gen)) “` Python DeveloperHard Try Now