-
Notifications
You must be signed in to change notification settings - Fork 0
Python
Python Questions
-
Decorator Usage: Write a Python decorator that logs the time taken by a function to execute.
-
List Comprehension: Use list comprehension to create a list of squares of numbers from 1 to 10.
-
Counter Usage: Given a list of words, use the Counter class from the collections module to count the frequency of each word.
-
Generator Function: Write a generator function that yields the Fibonacci sequence indefinitely.
-
Context Manager: Implement a context manager that measures the execution time of a code block using the
withstatement. -
Lambda Function: Use a lambda function to sort a list of tuples based on the second element of each tuple.
-
Map and Filter: Use map and filter functions to convert a list of strings to uppercase and filter out strings containing vowels.
-
Partial Function Application: Use the
functools.partialfunction to create a partial function that adds a fixed value to any number. -
JSON Parsing: Given a JSON string, parse it using the
jsonmodule and extract specific data fields. -
Regular Expressions: Write a regular expression to validate email addresses.
-
File Handling: Read data from a CSV file using the
csvmodule and calculate the total sum of a specific column. -
Class Inheritance: Create a class hierarchy with a base class and multiple derived classes, demonstrating inheritance and method overriding.
-
Exception Handling: Write code that demonstrates the use of try-except blocks to handle exceptions gracefully.
-
Dictionary Comprehension: Use dictionary comprehension to create a dictionary mapping each word in a list to its length.
-
Generator Expression: Use a generator expression to generate all prime numbers less than 1000.
-
Pickle Usage: Serialize and deserialize a Python object using the
picklemodule. -
Assertions: Write assertions to validate certain conditions in a function and raise appropriate errors if the conditions are not met.
-
Contextlib Module: Use the
contextlibmodule to create a context manager that suppresses a specific type of exception. -
String Formatting: Use f-strings or the
formatmethod to format strings with placeholders for variables. -
Datetime Module: Write code to calculate the difference between two dates using the
datetimemodule.