Triple the Numbers
Write a Python program to triple all numbers of a given sequence of integers.
# i/p: nums = (1, 2, 3, 4, 5, 6, 7)
# o/p: [3, 6, 9, 12, 15, 18, 21]
Write a Python program to add three given lists.
# input: nums1 = [1, 2, 3]
# nums2 = [4, 5, 6]
# nums3 = [7, 8, 9]
# output: [12, 15, 18]
Listify Strings Individually
Write a Python program to listify the list of given strings individually.
# input: l = [‘hello’, ‘world’]
# output: [[‘h’, ‘e’, ‘l’, ‘l’, ‘o’], [‘w’, ‘o’, ‘r’, ‘l’, ‘d’]]
Write a Python program to convert all the cases from lower to uppercase and upper to lowercase and eliminate duplicate letters from a given sequence.
# i/p: [‘a’, ‘b’, ‘E’, ‘f’, ‘a’, ‘i’, ‘o’, ‘U’, ‘a’]
# o/p: [‘A’, ‘B’, ‘e’, ‘F’, ‘I’, ‘O’, ‘u’]
Write a Python program to count the frequency of same pair(data) in two given lists.
# i/p: l1 = [1, 2, 3, 4, 5, 6, 7, 8]
# l2 = [2, 2, 3, 1, 2, 6, 7, 9]
# o/p: 4
Given an integer list. Create an output list storing all the factors of the given integer in tuple form.
# input: l = [12, 9, 10, 15]
# ol = [(1, 2, 3, 6, 12), (1, 3, 9), (1, 2, 5, 10), (1, 3, 5, 15)]
Mapping Purchases to Categories
– Fridge, AC, Washing Machine –> Electronics
– Fan, Motor –> Electricals
– Samsung S23, Apple 14 Pro Max, Motorola G85 –> Smartphones
– Mango, Apple, Banana, Pear –> Fruits
– Tshirt, Track Pant –> Clothes
Given an input list containing a list of items purchased by a user.
Create a list storing the category names as per the items purchased and the given mapping
Also, create a dictionary showing the frequency of items purchased per category.
Input: l = [‘Banana’, ‘Motor’, ‘Pear’, ‘Apple’, ‘Samsung S23’]
Output: ol = [‘Fruits’, ‘Electricals’, ‘Fruits’, ‘Fruits’, ‘Smartphones’]
od = {‘Electronics’: 0, ‘Electricals’:1, ‘Smartphones’: 1, ‘Fruits’:3, ‘Clothes’:0}
- Nested List Transformation
You are given a nested list where each sub-list contains numbers.
Create an output list where each sub-list contains the squared value of the original numbers.
Input: l = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
Output: ol = [[1, 4], [9, 16, 25], [36, 49, 64, 81]]
Replacing Vowels with a Symbol
Given a list of strings, replace all vowels in each string with a given symbol (e.g., ‘*’). Take the symbol as input.
Input: l = [‘hello’, ‘world’, ‘python’]
Output: ol = [‘h*ll*’, ‘w*rld’, ‘pyth*n’]
Transforming Strings Using Index Mapping
Given a list of words, create a list where each word is transformed by repeating its characters based on their index.
Input: l = [‘ab’, ‘cat’, ‘dogy’]
Output: ol = [‘abb’, ‘caattt’, ‘doogggyyyy’]
Mapping to Identify Palindromes
Given a list of strings, generate a boolean list where each element tells if the corresponding string is a palindrome (reads the same forwards and backwards).
Input: l = [‘madam’, ‘racecar’, ‘apple’, ‘level’, ‘python’]
Output: [True, True, False, True, False]
Convert Time from 12-Hour to 24-Hour Format
Given a list of times in 12-hour format (e.g., ’02:30 PM’), convert them into 24-hour format.
Input: l = [’12:00 AM’, ’01:30 PM’, ’11:45 PM’]
Output: [’00:00′, ’13:30′, ’23:45′]
Remove Vowels from Strings
Given a list of strings, remove all vowels from each string.
Input: l = [“apple”, “banana”, “grape”]
Output: [“ppl”, “bnn”, “grp”]
Identify Anagrams
Given two lists of words, check if corresponding words in the two lists are anagrams.
Input: l1 = [“listen”, “dusty”, “evil”]
l2 = [“silent”, “study”, “vile”]
Output: [True, True, True]
Calculate the Sum of Digits in Each Number
Given a list of integers, calculate the sum of digits for each number.
Input: l = [123, 456, 789]
Output: [6, 15, 24]
Count Uppercase and Lowercase Letters
Given a list of strings, count the number of uppercase and lowercase letters in each string.
Input: l = [“Hello”, “WORLD”, “PyThOn”]
Output: [(1, 4), (5, 0), (3, 3)]
Group Words by Length
Given a list of words, return a dictionary where the keys are word lengths, and the values are lists of words with the corresponding length.
Input: l = [‘cat’, ‘bat’, ‘tree’, ‘python’, ‘java’, ‘dog’]
Output: d = {3: [‘cat’, ‘bat’, ‘dog’], 4: [‘java’], 5: [‘tree’], 6: [‘python’]}
Increment Elements Based on their Index
Given a list of integers, increment each element by its index in the list.
Input: l = [10, 20, 30]
Output: ol = [10, 21, 32]
Explanation: Element 0 remains 10, element 1 becomes 21 (20 + 1), and element 2 becomes 32 (30 + 2)
Check for Perfect Squares
Given a list of integers, return a list indicating True or False for whether each number is a perfect square.
Input:
l = [1, 2, 4, 5, 9, 16]
Output: ol = [True, False, True, False, True, True]
Compute Hamming Distance between Strings
Given two lists of binary strings, compute the Hamming distance between corresponding strings
(i.e., the number of positions at which the corresponding bits are different).
Hamming Distance: For binary strings, Hamming distance indicates how many bits need to be changed to convert one binary string into the other.
Input: l1 = [“101”, “110”, “111”]
l2 = [“100”, “111”, “110”]
Output: ol = [1, 1, 2]