ASSIGNMENT 2
- Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings.Solution Sample List : [‘abc’, ‘xyz’, ‘aba’, ‘1221’] Expected Result : 2
- Write a Python program to get a list, sorted in increasing order by the last element in each tuple from a given list of non-empty tuples. Solution Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)] Expected Result : [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)].
-
Write a Python function that takes two lists and returns True if they have at least one common member.Solution a =[1, 2, 3, 4, 5] b =[6, 7, 8, 9] False
-
Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.Solution Sample List : [‘Red’, ‘Green’, ‘White’, ‘Black’, ‘Pink’, ‘Yellow’] Expected Output : [‘Green’, ‘White’, ‘Black’]
-
Write a Python program to print the numbers of a specified list after removing even numbers from it.Solution Enter number of elements : 7 7 8 120 25 44 20 27 [7, 25, 27]
-
Write a Python program to generate and print a list of first and last 5 elements where the values are square of numbers between 1 and 30 (both included).Solution
1 30 Output: [1, 4, 9, 16, 25] [625, 676, 729, 784, 841]
-
Write a Python program to generate and print a list except for the first 5 elements, where the values are square of numbers between 1 and 30 (both included).Solution
Enter lower limit : 1 Enter Upper limit : 30 [36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841
-
Write a Python program to find maximum and the minimum value in a set. Solution {5, 10, 3, 15, 2, 20} Maximum value of the said set: 20 Minimum value of the said set: 2
-
Write a Python program to find the length of a set.Solution {5, 5, 5, 5, 5, 5, 7} Length of the said set: 2
-
Write a Python program to check if a given value is present in a set or not.Solution Input: {4, 2, 9, 5, 1, 0, 7} element -> 5 Output: Present
-
Write a Python program to reverse a tuple.Solution (5, 10, 15, 20) (20, 15, 10, 5)
- Write a Python program to print a tuple with string formatting.Solution Sample tuple : (100, 200, 300) Output : This is a tuple (100, 200, 300)
-
Write a Python program to replace last value of tuples in a list.Solution Sample list: [(10, 20, 40), (40, 50, 60), (70, 80, 90)] Expected Output: [(10, 20, 100), (40, 50, 100), (70, 80, 100)]
-
Write a Python program to remove an empty tuple(s) from a list of tuples.Solution Sample data: [(), (), (‘’,), (‘a’, ‘b’), (‘a’, ‘b’, ‘c’), (‘d’)] Expected output: [(‘’,), (‘a’, ‘b’), (‘a’, ‘b’, ‘c’), ‘d’]
- Write a Python program to sort a tuple by its float element.Solution Sample data: [(‘item1’, ‘12.20’), (‘item2’, ‘15.10’), (‘item3’, ‘24.5’)] Expected Output: [(‘item3’, ‘24.5’), (‘item2’, ‘15.10’), (‘item1’, ‘12.20’)]