The ____ function in the functools module is used to transform a method into a class method decorator.
- classmethod
- decorator
- method2class
- staticmethod
The classmethod function in the functools module is used to transform a method into a class method decorator. Class methods can be called on the class itself rather than on instances of the class.
The ____ keyword in Python is used to define conditions under which a block of code will be executed.
- if
- switch
- try
- while
In Python, the 'if' keyword is used to define conditions for conditional execution of code blocks. Code within an 'if' block is executed only if the specified condition evaluates to true.
The ____ method in a metaclass is called when a new object is created from a class.
- __del__
- __init__
- __new__
- __str__
The __new__ method in a metaclass is called when a new object is created from a class. This method is responsible for creating and returning a new instance of the class.
The ____ method in generator objects is used to resume the generator and send a value back to it.
- next
- resume
- send
- yield
The send method is used to resume a generator and send a value back to it. This is commonly used for implementing two-way communication with a generator.
You need to build a RESTful API with Django that should include filtering, sorting, and pagination functionalities. How would you implement these functionalities efficiently?
- Manually implement filtering, sorting, and pagination logic in your Django views.
- Use Django REST framework, which provides built-in features for filtering, sorting, and pagination.
- Use JavaScript on the client-side for filtering, sorting, and pagination.
- Use plain Django views without any additional packages.
Django REST framework simplifies the process of building RESTful APIs and includes built-in support for filtering, sorting, and pagination. Manually implementing these features (Option 2) can be error-prone and time-consuming. Option 3 lacks the required features. Option 4 suggests client-side implementation, which may not be efficient or secure.
You need to create a data structure to hold a collection of elements, where each element has a unique key associated with it. Which Python data structure would you use?
- Dictionary
- List
- Set
- Tuple
In Python, a dictionary is the appropriate data structure for storing a collection of elements with unique keys. It allows efficient key-based access to elements, making it suitable for tasks like creating a mapping between keys and values.
You need to create a singleton class, i.e., a class that allows only one instance. Which Python concept can help you ensure that there is only one instance of the class in the system?
- Abstract Classes
- Decorators
- Private Methods
- Singleton Pattern
The Singleton Pattern is used to ensure that a class has only one instance and provides a way to access that instance from any point in the application. It typically involves creating a private constructor and a static method to retrieve the single instance.
You need to create a visualization that represents the correlation between all numerical variables in a dataset. Which kind of plot would you use in Seaborn?
- Bar Chart
- Box Plot
- Heatmap
- Scatter Plot
To visualize the correlation between numerical variables, a heatmap is typically used in Seaborn. It provides a color-coded matrix where each cell represents the correlation coefficient between two variables, making it easy to identify patterns and relationships.
You need to design a data structure that allows for retrieval of the most recently added element and removal of the least recently added element. How would you design such a data structure?
- Linked List
- Priority Queue
- Queue
- Stack
To achieve this behavior, you can use a Priority Queue. It maintains elements in a way that allows efficient retrieval of both the most recently added element and the removal of the least recently added element.
You need to design a system to find the top 10 most frequent words in a very large text corpus. Which data structures and algorithms would you use to ensure efficiency in both space and time?
- A) Array and Selection Sort
- B) Hash Map and Quick Sort
- C) Trie and Merge Sort
- D) Priority Queue (Heap) and Trie
To efficiently find the top 10 most frequent words, you should use a Priority Queue (Heap) to keep track of the top frequencies and a Trie or Hash Map to count word occurrences. A Trie can be used to efficiently store and retrieve words, while a Priority Queue helps maintain the top frequencies. The other options are less efficient in terms of both time and space complexity.