Basic Python
- Write a Python program which accepts the user's first and last name and prints them inreverse order with a space between them.
- Write a Python program which accepts a sequence of comma-separated numbers from theuser and generates a list and a tuple with those numbers. Sample data : 3, 5, 7, 23 Output : List : ['3', ' 5', ' 7', ' 23'] Tuple : ('3', ' 5', ' 7', ' 23')
- Write a Python program to display the first and last colours from the following list.color_list = ["Red","Green","White" ,"Black"]
- Write a Python program to print the documents (syntax, description etc.) of Python built-infunction(s). Sample function : abs() Expected Result : mat abs(number) -> number Return the absolute value of the argument.
- Write a Python program to print the calendar of a given month and year.Note : Use 'calendar' module.
- Write a Python program to calculate number of days between two dates. Sample dates : (2014, 7, 2), (2014, 7, 11) Expected output : 9 days
- Write a Python program to check whether a specified value is contained in a group of values.Test Data : 3 -> [1, 5, 8, 3] : True -1 -> [1, 5, 8, 3] : False
- Write a Python program to create a histogram from a given list of integers.
- Write a Python program to concatenate all elements in a list into a string and return it.
- Write a Python program to print out a set containing all the colors from color_list_1 which arenot present in color_list_2. Test Data : color_list_1 = set(["White", "Black", "Red"]) color_list_2 = set(["Red", "Green"]) Expected Output : {'Black', 'White'}
- Write a Python program to check whether a file exists.
- Write a python program to call an external command in Python.
- Write a Python program to find out the number of CPUs using.
- Write a Python program to list all files in a directory in Python.
- Write a python program to access environment variables.
- Write a Python program to get the current username
- Write a program to get execution time for a Python method.
- Write a Python program to get an absolute file path.
- Write a Python program to get file creation and modification date/times.
- Write a Python program to sort three integers without using conditional statements andloops.
- Write a Python program to sort files by date.
- Write a Python program to get the command-line arguments (name of the script, the numberof arguments, arguments) passed to a script.
- Write a Python program to find the available built-in modules.
- Write a Python program to get the size of an object in bytes.
- Write a Python program to get the current value of the recursion limit.
- Write a Python program to count the number occurrence of a specific character in a string.
- Write a Python program to get the system time.
- Write a Python program to clear the screen or terminal.
- Write a Python program to get the name of the host on which the routine is running.
- Write a Python program to access and print a URL's content to the console. Python Data Structure Array
- Write a Python program to create an array of 5 integers and display the array items.Access individual element through indexes.
- Write a Python program to reverse the order of the items in the array.
- Write a Python program to get the number of occurrences of a specified element in anarray.
- Write a Python program to remove the first occurrence of a specified element from anarray. Dictionary
- Write a Python script to sort (ascending and descending) a dictionary byvalue.
- Write a Python script to add a key to a dictionary. Sample Dictionary : {0: 10, 1: 20} Expected Result : {0: 10, 1: 20, 2: 30}
- Write a Python script to concatenate following dictionaries to create a newone. Sample Dictionary : dic1={1:10, 2:20} dic2={3:30, 4:40} dic3={5:50,6:60} Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
- Write a Python program to iterate over dictionaries using for loops.
- Write a Python script to generate and print a dictionary that contains anumber (between 1 and n) in the form (x, x*x). Sample Dictionary ( n = 5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
- Write a Python program to remove a key from a dictionary.
- Write a Python program to print all unique values in a dictionary. Sample Data : [{"V":"S001"}, {"V": "S002"}, {"VI": "S001"}, {"VI": "S005"}, {"VII":"S005"}, {"V":"S009"},{"VIII":"S007"}] Expected Output : Unique Values: {'S005', 'S002', 'S007', 'S001', 'S009'}
- Write a Python program to create a dictionary from a string. Note: Track the count of the letters from the string. Sample string : 'w3resource' Expected output: {'3': 1, 's': 1, 'r': 2, 'u': 1, 'w': 1, 'c': 1, 'e': 2, 'o': 1}
- Write a Python program to print a dictionary in table format.
- Write a Python program to count the values associated with key in adictionary. Sample data: = [{'id': 1, 'success': True, 'name': 'Lary'}, {'id': 2, 'success': False, 'name': 'Rabi'}, {'id': 3, 'success': True, 'name': 'Alex'}] Expected result: Count of how many dictionaries have success as True
- Write a Python program to convert a list into a nested dictionary of keys.
- Write a Python program to check multiple keys exists in a dictionary.
- Write a Python program to count number of items in a dictionary value that is a list. Sets
- Write a Python program to create a set.
- Write a Python program to iteration over sets.
- Write a Python program to add member(s) in a set.4. Write a Python program to remove item(s) from set
- Write a Python program to remove an item from a set if it is present in the set.
- Write a Python program to create an intersection of sets.
- Write a Python program to create a union of sets.
- Write a Python program to create set difference.
- Write a Python program to create a symmetric difference.
- Write a Python program to clear a set.
- Write a Python program to use of frozensets.
- Write a Python program to find maximum and the minimum value in a set. List
- Write a Python program to sum all the items in a list.
- Write a Python program to multiplies all the items in a list.
- Write a Python program to get the smallest number from a list.
- Write a Python program to count the number of strings where the string lengthis 2 or more and the first and last character are same from a given list of strings. Sample List : ['abc', 'xyz', 'aba', '1221'] Expected Result : 2
- Write a Python program to get a list, sorted in increasing order by the lastelement in each tuple from a given list of non-empty tuples. Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)] Expected Result : [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)] 6. Write a Python program to remove duplicates from a list.
- Write a Python program to clone or copy a list.
- Write a Python program to find the list of words that are longer than n from agiven list of words.
- Write a Python function that takes two lists and returns True if they have atleast one common member.
- Write a Python program to print a specified list after removing the 0th, 4th and5th elements. Sample List : ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow'] Expected Output : ['Green', 'White', 'Black']
- Write a Python program to generate all permutations of a list in Python.
- Write a Python program to get the difference between the two lists.
- Write a Python program to append a list to the second list.
- Write a python program to check whether two lists are circularly identical.
- Write a Python program to find common items from two lists.
- Write a Python program to split a list based on first character of word.
- Write a Python program to remove duplicates from a list of lists. Sample list : [[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]] New List : [[10, 20], [30, 56, 25], [33], [40]] Tuple
- Write a Python program to create a tuple.
- Write a Python program to create a tuple with different data types.
- Write a Python program to unpack a tuple in several variables.
- Write a Python program to create the colon of a tuple.
- Write a Python program to find the repeated items of a tuple.
- Write a Python program to check whether an element exists within a tuple.
- Write a Python program to convert a list to a tuple.
- Write a Python program to remove an item from a tuple.
- Write a Python program to slice a tuple.
- Write a Python program to reverse a tuple. Strings
- Write a Python program to calculate the length of a string.
- Write a Python program to count the number of characters (character frequency) in astring. Sample String : google.com Expected Result : {'o': 3, 'g': 2, '.': 1, 'e': 1, 'l': 1, 'm': 1, 'c': 1}
- Write a Python program to get a string from a given string where all occurrences of itsfirst char have been changed to '$', except the first char itself. Sample String : 'restart' Expected Result : 'resta$t'
- Write a Python program to add 'ing' at the end of a given string (length should be atleast 3). If the given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is less than 3, leave it unchanged. Sample String : 'abc' Expected Result : 'abcing' Sample String : 'string' Expected Result : 'stringly'
- Write a Python function that takes a list of words and returns the length of the longestone.
- Write a Python script that takes input from the user and displays that input back inupper and lower cases.
- Write a Python program that accepts a comma separated sequence of words as inputand prints the unique words in sorted form (alphanumerically). Sample Words : red, white, black, red, green, black Expected Result : black, green, red, white,red
- Write a Python program to get the last part of a string before a specified character. https://www.w3resource.com/python-exercises https://www.w3resource.com/python
- Write a Python program to display formatted text (width=50) as output.
- Write a Python program to count occurrences of a substring in a string.
- Write a Python program to reverse a string.
- Write a Python program to lowercase first n characters in a string.