/ Home
Python Assignments
Note: 1000 Assignments
1. List
Basic
- Create a Python program to input 5 integers and store them in a list. Print the sum and average of the list elements.
- Write a function that removes duplicates from a list.
- Create a list of numbers and print only the even numbers.
- Reverse a given list using slicing and print it.
-
Create a list of strings and check if a specific string exists in the list.
- Write a program to find the index of a specific element in a list.
- Create a program to input a list of integers and sort them in ascending order.
- Write a function to count the occurrences of a specific element in a list.
- Create a list of random numbers and print the largest and smallest values.
- Write a program to concatenate two lists and remove duplicates.
Intermediate
- Write a program to rotate a list by n positions to the left.
- Implement a program to merge two sorted lists into one sorted list.
- Find the second largest and second smallest numbers in a list.
- Implement a function to count the frequency of each element in a list.
-
Create a list of tuples where each tuple contains a number and its square.
- Implement a program to split a list into two halves.
- Write a program to find the intersection of two lists.
- Create a program to remove all elements from a list that are greater than a given threshold.
- Write a function to flatten a nested list.
- Implement a program to group elements of a list into chunks of a specified size.
Advanced
- Implement a program to find all subsets of a list.
- Create a program to partition a list into two based on a condition (e.g., greater than a threshold).
- Write a program to find all unique permutations of a given list.
- Implement a dynamic program to find the maximum sum subarray in a list.
-
Create a sparse matrix representation using lists and implement addition for two such matrices.
- Write a program to perform matrix multiplication using nested lists.
- Create a program to generate all possible combinations of elements in a list of length n.
- Implement a function to find the longest increasing subsequence in a list.
- Write a program to shuffle the elements of a list randomly.
- Design a function to merge overlapping intervals in a list of tuples.
2. IP Utils
Basic
- Write a program to validate an IPv4 address format.
- Extract the network ID from a given IP address and subnet mask.
- Count the number of host IPs possible in a given subnet.
- Check if two IP addresses belong to the same subnet.
- Write a program to convert an IP address into binary format.
Intermediate
- Create a CIDR calculator that outputs the network ID, broadcast address, and usable IP range.
- Develop a program to generate all possible IP addresses from a given string of digits.
- Write a program to find the class (A, B, C, D, or E) of an IP address.
- Implement a tool to compare two IP addresses and determine their relationship in terms of network hierarchy.
- Create a program to calculate the distance (number of bits) between two IP addresses.
Advanced
- Implement a program that identifies overlapping subnets from a list of CIDR notations.
- Create a utility to compress and expand IPv6 addresses.
- Build a tool to generate subnet allocation for a given IP block and required subnets.
- Design a program to validate and parse a mixed list of IPv4 and IPv6 addresses.
- Implement an IP address obfuscator and deobfuscator.
2. IP Utils
Basic
- Write a program to convert an IP address from dotted-decimal notation to integer format.
- Create a function to generate the broadcast address of a given IP and subnet mask.
- Write a program to check if an IP address is private or public.
- Develop a utility to validate if an IP belongs to a given CIDR range.
- Implement a program to calculate the total number of subnets possible for a given network mask.
Intermediate
- Write a function to split a large subnet into smaller subnets of a given size.
- Create a program to find the next available IP address in a subnet.
- Write a utility to convert an IP address into hexadecimal format.
- Implement a function to classify IP addresses as reserved or assignable.
- Create a program to validate subnet masks and ensure they are in valid CIDR format.
Advanced
- Develop a tool to find the longest prefix match for a given IP address in a list of CIDR blocks.
- Write a program to generate hierarchical IP allocation for ISPs.
- Implement an IP address summarization tool to aggregate multiple CIDR blocks into the smallest possible range.
- Create a tool to detect duplicate IPs in a large dataset.
-
Design an advanced firewall rule simulator to test IP filtering.
3. Set
Basic
- Create a set of integers and perform union, intersection, and difference operations.
- Write a program to check if one set is a subset of another.
- Find the symmetric difference between two sets.
- Remove all duplicates from a list using a set.
- Write a program to check if two sets are disjoint.
Intermediate
- Implement a function to find all elements that are present in exactly one of the two sets.
- Write a program to generate a set of all common elements in multiple sets.
- Create a program to find the Cartesian product of two sets.
- Implement a function to find the power set of a given set.
- Write a program to find the longest set of consecutive integers in a list.
Advanced
- Implement a program to solve the set cover problem.
- Write a program to efficiently find minimal hitting sets for a collection of sets.
- Create a utility to compare two sets for structural equivalence under transformations.
- Build a program to generate all possible partitions of a set.
- Implement an algorithm to compute the difference between two sets using Bloom filters.
3. Set
Basic
- Write a program to find common elements between two sets of strings.
- Create a set from a string, removing duplicate characters.
- Write a program to check if one set is a proper subset of another.
- Implement a function to clear all elements from a set.
- Create a program to find the union of multiple sets.
Intermediate
- Write a function to find all unique combinations of elements from two sets.
- Create a program to determine the Jaccard similarity between two sets.
- Write a program to find elements that appear in at least two of three sets.
- Implement a program to merge two sets with priority given to one for duplicate elements.
- Write a program to compute the complement of a set within a universal set.
Advanced
- Create a program to find the maximum independent set in a graph using sets.
- Write a tool to solve the subset sum problem using sets.
- Implement a function to compare and rank multiple sets by their cardinality.
- Develop a tool to calculate the transitive closure of relations represented by sets.
-
Create a program to generate all minimal covers of a set.
4. Method
Basic
- Write a class with instance methods to calculate the area and perimeter of a rectangle.
- Create a class with static methods for basic mathematical operations (addition, subtraction, multiplication, and division).
- Implement a class with a method that accepts a list and returns the reversed list.
- Write a method to convert a string to uppercase and lowercase.
- Implement a class method to count the number of instances created.
Intermediate
- Design a class with overloaded methods for handling various types of input.
- Write a program to define and call a private method within a class.
- Implement a method that accepts variable-length arguments and calculates their product.
- Create a class with a method to count vowels in a given string.
- Develop a method to validate and format phone numbers using regular expressions.
Advanced
- Implement a factory method pattern to create instances of various shapes.
- Create a class with methods for matrix operations (addition, multiplication, transposition).
- Write a program to implement and use the singleton design pattern.
- Develop a method that uses reflection to inspect methods of another class at runtime.
- Build a class with methods to handle file encryption and decryption.
4. Method
Basic
- Add a method to a class that converts an attribute value into JSON format.
- Write a method that checks if a number is prime.
- Implement a class method to compare two objects of the same class by their attributes.
- Write a method that calculates the area of a triangle given its base and height.
- Implement a method to reverse a string without using built-in functions.
Intermediate
- Create a method to calculate the compound interest given principal, rate, and time.
- Implement a class with methods to handle string encryption and decryption using a simple cipher.
- Add a method to a class to find the nth Fibonacci number recursively.
- Write a method to determine if a given year is a leap year.
- Implement a method to find all palindromic substrings in a given string.
Advanced
- Design a class with methods to parse and evaluate mathematical expressions.
- Implement a class method to dynamically create an instance from a dictionary of attributes.
- Write a program to handle method overloading using
*argsand**kwargs. - Create a method to visualize data as a bar chart using a text-based interface.
-
Develop a class with methods to interact with external APIs and handle JSON responses.
5. Class
Basic
- Create a
Studentclass with attributes for name, roll number, and grade. Add methods to display the student details. - Implement a
BankAccountclass with methods to deposit, withdraw, and check the balance. - Write a
Carclass with attributes for brand, model, and year. Add a method to display the car details. - Define a class with a method to calculate the factorial of a number.
- Implement a
Personclass with anintroducemethod.
Intermediate
- Design a class to represent a 2D point and implement methods for distance calculation and midpoint.
- Create a
Bookclass with attributes and methods to manage a book inventory system. - Write a
Circleclass with methods to calculate area and circumference. - Implement a class with methods for handling employee payroll.
- Develop a
Loggerclass to log messages with timestamps.
Advanced
- Implement a class hierarchy with inheritance to model geometric shapes (e.g., circle, rectangle, triangle).
- Build a thread-safe implementation of a custom
Queueclass. - Design a
Graphclass with methods for depth-first and breadth-first traversal. - Implement a
Databaseclass to interact with an SQLite database. - Develop a class for handling complex numbers with operator overloading.
5. Class
Basic
- Create a
Calculatorclass with methods for basic arithmetic operations. - Write a
Shapeclass with attributes for color and a method to display the color. - Create a
Clockclass with a method to display the current time. - Write a
Studentclass with a method to calculate the GPA from a list of grades. - Implement a
Dogclass with attributes for breed, age, and methods to perform basic actions like barking.
Intermediate
- Create a
Polygonclass with methods to calculate perimeter and area for different polygons. - Write a
Movieclass to manage a movie database with methods to add, remove, and search for movies. - Implement a
Bankclass with methods to transfer money between accounts. - Design a
Weatherclass to fetch and display current weather using an API. - Develop a
Productclass to manage inventory with methods for restocking and tracking sales.
Advanced
- Build a class hierarchy for a transportation system, including vehicles like cars, bikes, and buses.
- Write a
Libraryclass to manage book rentals and returns, tracking overdue books. - Implement a
Workflowclass to model and execute tasks in a directed acyclic graph. - Create a
DataFrameclass with methods to filter, sort, and summarize data. - Design a class to simulate an event-driven system with a queue of events.
6. Logger
Basic
- Set up a basic logger to log messages to a file.
- Configure a logger to display different log levels (DEBUG, INFO, WARNING, ERROR).
- Write a program to log user inputs to a file.
- Create a logger with timestamps in each log message.
- Set up a rotating file logger.
Intermediate
- Write a logger to log API requests and responses to a file.
- Configure a logger to send critical logs via email.
- Create a hierarchical logger with multiple modules logging to different files.
- Add custom log formatting for better readability.
- Implement a logger that logs to both a file and the console.
Advanced
- Write a program to log exceptions and errors with traceback details.
- Build a logging decorator to log function calls and arguments.
- Implement a centralized logging system for a distributed application.
- Create a logger that integrates with external monitoring tools.
- Design a logger with dynamic log level changes at runtime.
6. Logger
Basic
- Set up a logger to log messages with different formats for INFO and ERROR levels.
- Write a logger to log function start and end times.
- Create a logger that logs only messages above a specific severity level.
- Write a program to log user login attempts to a file.
- Implement a logger that logs the size of the log file after every entry.
Intermediate
- Create a logger that archives old logs into a zip file periodically.
- Write a logger to track and log memory usage of a program.
- Develop a logger to trace the execution flow of recursive functions.
- Write a program to log incoming and outgoing messages in a chat application.
- Implement a logger with custom levels for application-specific events.
Advanced
- Build a distributed logger to collect logs from multiple servers into a centralized database.
- Create a logger to analyze and report trends in logged messages over time.
- Implement a logger that integrates with Elasticsearch for log storage and visualization.
- Write a logger that uses machine learning to identify anomalies in log patterns.
- Develop a logger to track and measure performance bottlenecks in a web application.
7. Decorator
Basic
- Write a decorator to measure the execution time of a function.
- Create a decorator to log function calls.
- Implement a decorator to validate input arguments of a function.
- Write a decorator to retry a function in case of failure.
- Design a decorator to cache the result of a function.
Intermediate
- Create a decorator to enforce a rate limit on function calls.
- Write a decorator that modifies the output of a function.
- Implement a decorator to convert function arguments to uppercase.
- Create a decorator to automatically handle exceptions in a function.
- Write a chainable decorator for logging and execution time measurement.
Advanced
- Build a class-based decorator to manage database connections.
- Implement a decorator for lazy evaluation in a class.
- Write a meta-decorator that can enhance other decorators.
- Develop a decorator for access control in a web application.
- Create a decorator to transform synchronous functions into asynchronous ones.
7. Decorator
Basic
- Write a decorator to add timestamps to log messages.
- Create a decorator to validate the data type of function arguments.
- Write a decorator to automatically retry a function upon failure, with exponential backoff.
- Develop a decorator to memoize the results of expensive functions.
- Create a decorator to log the arguments and return values of a function.
Intermediate
- Write a decorator to limit the execution of a function to once every n seconds.
- Implement a decorator that checks for required permissions before executing a function.
- Write a decorator to handle timeout for long-running functions.
- Create a decorator to throttle API calls to a specific rate.
- Write a decorator to enable lazy evaluation of function results.
Advanced
- Create a decorator to profile and visualize function execution time.
- Write a decorator to dynamically modify class methods based on runtime conditions.
- Implement a decorator for distributed locking using Redis.
- Develop a decorator for transactional operations with automatic rollback on failure.
- Build a decorator to enforce input and output constraints using Python type hints.
8. Dateutil
Basic
- Parse a date string into a
datetimeobject. - Add 7 days to the current date and print the result.
- Calculate the difference between two dates.
- Write a program to get the day of the week for a given date.
- Format a date in multiple formats using
strftime.
Intermediate
- Parse and handle ISO 8601 date strings.
- Generate a list of all dates between two given dates.
- Implement a program to find the next weekday after a given date.
- Write a program to calculate the number of weekends in a year.
- Create a recurring event scheduler with customizable intervals.
Advanced
- Write a program to handle time zone conversions.
- Create a program to calculate the date of Easter for any given year.
- Implement a utility to parse and calculate relative time deltas (e.g., “2 weeks ago”).
- Build a date range merging tool.
- Write a tool to normalize dates in text using
dateutil.
8. Dateutil
Basic
- Write a program to determine the number of days in a month for a given year.
- Create a utility to add or subtract months from a given date.
- Write a program to find the difference in time between two given timestamps.
- Create a program to display the last day of the current month.
- Implement a program to parse and validate dates in multiple formats.
Intermediate
- Write a program to calculate the age of a person given their birthdate.
- Implement a program to find the number of weekdays between two dates.
- Create a scheduler to trigger events every nth day.
- Write a program to handle daylight saving time transitions.
- Implement a function to find all holidays in a given date range.
Advanced
- Write a tool to convert between different calendar systems (Gregorian, Julian, etc.).
- Create a program to schedule recurring tasks with custom intervals (e.g., every 3rd Tuesday).
- Build a date range overlap detection utility for bookings or reservations.
- Write a program to synchronize and normalize dates across time zones.
- Develop a program to calculate accurate durations across leap seconds.
9. Argsparser
Basic
- Create a script that accepts a name and age as arguments and prints a greeting.
- Write a program to handle optional arguments with default values.
- Implement a script to accept a file path as an argument and print the file content.
- Add a flag to a script to enable verbose output.
- Write a script to accept a list of numbers and print their sum.
Intermediate
- Implement a script with subcommands for addition, subtraction, multiplication, and division.
- Add a custom help message to a script using
argparse. - Create a script to accept multiple arguments and validate their types.
- Write a script to parse and handle a configuration file path as an argument.
- Implement argument groups for better organization of command-line options.
Advanced
- Create a script with nested subcommands for complex workflows.
- Implement a CLI tool with dynamic argument parsing based on a configuration file.
- Write a program to generate and validate argument constraints (e.g., number range).
- Develop a CLI tool with integration for auto-completion.
- Build a fully-featured command-line tool with custom error handling.
9. Argsparser
Basic
- Write a script to accept a list of file paths and print their existence.
- Create a CLI tool with options for verbose and silent modes.
- Write a script to accept user credentials (username, password) as arguments.
- Implement a program to display help text and argument defaults.
- Create a tool to accept multiple file extensions and filter a directory’s files.
Intermediate
- Write a program to accept arguments for connecting to a database (host, port, user, password).
- Implement a script with mutually exclusive arguments.
- Create a CLI for a calculator with arguments for operation type and operands.
- Write a script that parses arguments for configuring logging levels and formats.
- Implement a tool to parse nested configuration options.
Advanced
- Write a program to generate a dynamic argument parser from a JSON configuration file.
- Develop a script that supports dynamic subcommands based on plugins.
- Create a CLI tool that uses argument validation with custom error messages.
- Implement a program that stores and retrieves arguments from a cache file.
- Build a CLI tool that allows argument combinations and dependencies.
10. Caching
Basic
- Implement a simple in-memory cache using a dictionary.
- Write a program to cache the results of a function using
functools.lru_cache. - Create a program to cache API responses for a fixed duration.
- Implement a manual caching system with expiration using a dictionary.
- Write a program to count cache hits and misses.
Intermediate
- Create a decorator-based caching mechanism with custom eviction policies.
- Implement a program to save and load cache data to/from a file.
- Write a multi-layered caching system with memory and disk layers.
- Build a caching mechanism for database queries.
- Write a program to implement a Least Recently Used (LRU) cache.
Advanced
- Implement a distributed caching system using
Redis. - Write a caching library with support for different backend stores (e.g., memory, file, Redis).
- Create a utility to cache function outputs based on input arguments.
- Develop a cache-aware API client with support for stale-while-revalidate caching.
- Build a program to analyze cache performance metrics in real-time.
10. Caching
Basic
- Write a program to cache user preferences in a dictionary.
- Create a simple caching mechanism with time-based invalidation.
- Implement a caching system for storing and retrieving website session data.
- Write a program to cache the results of a function with default and custom keys.
- Create a script to preload and cache configuration data for a tool.
Intermediate
- Implement a caching mechanism that writes to disk when memory usage exceeds a threshold.
- Write a program to manage a shared cache for concurrent threads.
- Build a utility to cache API responses with support for cache invalidation by URL pattern.
- Create a program to manage a cache with a size limit and eviction policy (FIFO).
- Develop a function-level cache decorator that tracks hits, misses, and evictions.
Advanced
- Build a distributed cache system using
Memcached. - Implement a hierarchical cache system with local and remote cache layers.
- Create a program to serialize and store cache data in a database.
- Design a caching system with predictive prefetching based on usage patterns.
- Develop a tool to measure and optimize cache hit rates for performance tuning.
1. List
Basic
- Create a list of integers and replace all odd numbers with -1.
- Write a program to count how many times a particular element appears in a list.
- Reverse a list without using slicing or the reverse() method.
- Write a function to double each element in a list.
- Create a list from a string, where each character is an element.
- Write a program to find the sum of all elements in a list using a loop.
- Create a program to append one list to another.
- Write a program to find the index of the maximum element in a list.
- Generate a list of square numbers for the first 10 integers.
- Write a function to remove all occurrences of a specific element from a list.
Intermediate
- Implement a function to find the longest consecutive subsequence in a list.
- Write a program to rotate a list n positions to the right.
- Create a list of tuples where each tuple contains a number and its factorial.
- Write a function to merge overlapping intervals in a list of ranges.
- Implement a program to generate a list of prime numbers within a range.
- Write a function to find the union of two lists without duplicates.
- Create a program to partition a list into sublists of a given size.
- Write a function to split a list into a list of even and odd numbers.
- Implement a function to remove every nth element from a list.
- Write a program to find the three largest numbers in a list.
Advanced
- Create a program to efficiently find all distinct triplets in a list that sum up to a given value.
- Write a program to generate all possible subsets of a list and count how many subsets have an even sum.
- Implement a function to convert a list of integers into their Roman numeral representations.
- Write a function to find the most frequent element in a list.
- Design a program to perform polynomial addition using lists of coefficients.
- Create a sparse matrix using nested lists and implement its addition and multiplication.
- Write a program to convert a list of nested dictionaries into a flat dictionary.
- Create a function to find the longest common subsequence between two lists.
- Write a program to rearrange a list so that all negative numbers appear before positive ones, without changing their relative order.
- Implement a program to sort a list of custom objects based on multiple attributes.
2. IP Utils
Basic
- Write a program to calculate the network prefix length from a subnet mask.
- Create a program to list all possible IP addresses in a /24 subnet.
- Write a program to classify an IP address as unicast, multicast, or reserved.
- Create a function to determine the last usable host IP in a subnet.
- Write a program to extract the octets of an IP address and print them.
- Implement a function to count the number of bits set in an IP address.
- Write a program to check if a given IP address is valid.
- Implement a function to calculate the wildcard mask of a given subnet.
- Create a tool to extract the network address from an IP address and subnet mask.
- Write a program to find the next higher subnet that can include a given IP range.
Intermediate
- Create a program to merge two or more IP ranges into the smallest set of ranges.
- Write a tool to determine the overlap between two IP ranges.
- Create a function to find the first n usable host IPs in a subnet.
- Write a program to calculate the percentage of usable IPs in a given range.
- Create a program to generate a list of random IP addresses in a given subnet.
- Write a program to identify all broadcast addresses in a given range of subnets.
- Implement a function to determine the CIDR notation of an IP range.
- Create a program to calculate the total number of networks possible for a given mask length.
- Write a program to sort a list of IP addresses numerically.
- Implement a function to check if an IP is valid based on specific custom rules (e.g., not starting with certain octets).
Advanced
- Build a tool to perform IP subnet optimization, grouping smaller subnets into larger ones.
- Write a program to simulate an IP address allocation system for a data center.
- Create a utility to parse and validate a configuration file containing mixed IPv4/IPv6 ranges.
- Design a function to convert between IPv4-mapped IPv6 addresses and standard IPv4.
- Implement an IP tracking tool to detect duplicates and unused addresses in a dynamic environment.
- Write a tool to generate a heatmap of subnet usage from a list of IP allocations.
- Create an IP conflict resolution utility to suggest alternate ranges.
- Build a tool to calculate and visualize subnet hierarchy for a given CIDR block.
- Implement an advanced firewall rule simulator to test packet acceptance based on IP filtering.
- Write a program to detect and classify rogue subnets from a list of routing table entries.
3. Set
Basic
- Write a program to check if a given set is empty.
- Create a program to add multiple elements to a set.
- Write a function to return the elements in one set but not in another.
- Create a program to remove the smallest element from a set of numbers.
- Implement a function to find all elements common to two sets.
- Write a program to find the length of a set.
- Create a program to clear all elements from a set.
- Write a function to copy the contents of one set to another.
- Create a program to find the maximum element in a numeric set.
- Write a program to check if two sets are equal.
Intermediate
- Implement a program to determine if two sets have any common elements.
- Write a function to find all subsets of a set.
- Create a program to compute the symmetric difference between multiple sets.
- Write a program to generate the Cartesian product of three sets.
- Create a utility to identify the smallest set from a list of sets.
- Write a program to remove all elements from a set that are present in another set.
- Implement a function to find the union of an arbitrary number of sets.
- Create a tool to find the intersection of multiple sets.
- Write a program to create a frozen set and demonstrate its immutability.
- Implement a function to compare two sets for structural equivalence.
Advanced
- Build a program to compute the transitive closure of a relation represented as sets.
- Write a function to solve the k-set partitioning problem.
- Create a tool to determine if a collection of sets is disjoint.
- Write a program to efficiently compute the difference between sets using hash-based methods.
- Implement a function to generate all distinct partitions of a set.
- Design a set-based caching mechanism to track unique API calls.
- Create a tool to detect redundant elements in a collection of overlapping sets.
- Write a program to compute the union-find structure of disjoint sets.
- Implement a set similarity tool using Jaccard or Cosine similarity measures.
- Develop an algorithm to solve the minimal covering set problem for a collection of subsets.
Let me know if you’d like me to continue with the remaining subtopics!