Python Questions
Python Questions
Expected Output:
input: acdfksekfevskdjfs
Output: 1
Expected Output:
Expected Output:
74. Everyone knows that chotu likes palindromic strings. One day, he found 2 ordinary strings s1
and s2. Now he wonders if he could make a palindrome by concatenating s1 and s2 in any
order. i.e if s1s2 or s2s1 is a palindrome.
75. Chandu is very fond of strings. (Or so he thinks!) But, he does not like strings which have
same consecutive letters. No one has any idea why it is so. He calls these strings as Bad
strings. So, Good strings are the strings which do not have same consecutive letters. Now,
the problem is quite simple. Given a string S, you need to convert it into a Good String. You
simply need to perform one operation - if there are two same consecutive letters, delete one
of them.
SAMPLE INPUT
3
abb
aaab
ababa
SAMPLE OUTPUT
ab
ab
ababa
76. Write a program to find the avg. of given numbers in a list.
77. Find and delete the duplicate elements in a list.
78. Store and print even and odd numbers in two different lists.
79. Find largest odd and largest even in a list.
80. Find intersection of 2 lists.
81. Python Program to Merge Two Lists and Sort it.
82. Python Program to Find the Second Largest Number in a List.
83. Python Program to Generate Random Numbers from 1 to 20 and Append Them to the List
84. Python Program to Read a List of Words and Return the Length of the Longest One.
85. Python Program to Swap the First and Last Value of a List.
86. Python Program to Remove the ith Occurrence of the Given Word in a List where Words can
Repeat.
87. Python Program to Find the Largest Number in a List.
88. Given an integer array, for each element in the array check whether there exist a
smaller element on the next immediate position of the array. If it exist print the smaller
element. If there is no smaller element on the immediate next to the element then print -1.
Example Input: 4 2 1 5 3 Output: 2 1 -1 3 -1
89. Write a Pandas program to select the rows where the number of attempts in the
examination is greater than 2.
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
90. Write a Pandas program to add one row and one column in an existing DataFrame.
91. Write a Pandas program to count city wise number of people from a given of data set (city,
name of the person).
link: https://www.w3resource.com/python-exercises/pandas/python-pandas-data-frame-
exercise-28.php
92. Write a Pandas program to replace all the NaN values with mean in a column of a dataframe.
93. Write a python program to create data frame using a dictionary with the name Employee
with titles as Empid, Empname, Empdesig. Insert 10 records into it and display them. Add
the title Empcontact as a new title and display the results.
94. With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one
line and the last half values in one line.
95. Write a program to read the information present in a welcome1.txt file such as student
name, roll no and also append the information such as contact address, parent details, and
city zip code and display it.
96. Write a program to count the vowels, consents, digits, and special symbols present in a file.
97. Write a python program to data frame using dictionary with the name Student with titles as
Stuid, Stuname, and StuNo. Insert 10 records into it and display them. Add the title
Studentemail as a new title and display the results.
98. Write a program to create a tuple and perform the operations of insertion, deletion, append,
and change the information in it.
99. Write a program to merge the two files and display the information.
100. Write a program to copy the information present in one file to another file.
101. Given is a data frame showing the name, occupation, salary of people. Find the
average salary per occupation.
102. Write a python program to check whether a given no is strong no or not using
functions.
103. Write a python program to check whether a given no is prime no or not using
functions.
104. Python program to Sort a List of Tuples in Increasing Order by the Last Element in
Each Tuple.
105. Program to get the difference between the two tuples.
106. Given list of tuples, remove all the tuples with length K. Input : test_list = [(4, 5), (4, ),
(8, 6, 7), (1, ), (3, 4, 6, 7)], K = 2 Output : [(4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] Explanation : (4, 5) of
len = 2 is removed.
107. Program to generate and print a dictionary that contains a number (between 1 and
n) in the form (x, x*x). Sample Input: (n=5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
108. Program to get the maximum and minimum value in a dictionary.
109. Given an integer tuple, for each element in the tuple check whether there exist a
smaller element on the next immediate position of the array. If it exist print the smaller
element. If there is no smaller element on the immediate next to the element then print -1.
110. Example Input: 4 2 1 5 3 Output: 2 1 -1 3 -1
111. Python Program to Generate Random Numbers from 1 to 20 and Append Them to
the Tuple.
112. Write a python program to find the prime factors of a given number using functions.
113. Write a python program that takes an integer and forms a new integer which has
the number of digits at the ten’s place and the least significant digit in the one’s place using
functions. For ex, 452 => 32
114. Write a program to explore all 11 attributes of series in pandas.
115. Write a pandas program to remove the duplicates in a student dataset.
116. Write a pandas program to export the dataframe to excel file using any employee
dataset.
117. Write a pandas program to display employee details whose salary is >25000 and
<50000, from employee dataset and also display employee names contains character ‘s’
using compound condition.
118. Write a pandas program to apply conditional changes on employee dataset using
salary column on designation column. (Based on salaries of the employees create a new
column and assign designations to them)
119. Write a Python program to check that a string contains only a certain set of
characters (in this case a-z, A-Z and 0-9).
120. Write a Python program that matches a string that has an a followed by one or more
b's.
121. Write a Python program that matches a string that has an 'a' followed by anything
ending in 'b'.
122. Write a Python program that matches a word at the beginning of a string.
123. Write a Python program that matches a word at the end of a string, with optional
punctuation.
124. Write a Python program to remove leading zeros from an IP address.
125. Write a Python program to extract year, month and date from an URL.
126. Write a Python program to match if two words from a list of words start with the
letter 'P'.
127. Write a Python program to abbreviate 'Road' as 'Rd.' in a given string.
128. Write a Python program to replace maximum 2 occurrences of space, comma, or dot
with a colon.
129. Write a Python Extract values between quotation marks of a string
130. Write a Python program to check a decimal with a precision of 2.
131. Write a Python program to insert spaces between words starting with capital letters.
132. Write a Python program to convert a camel-case string to a snake-case string.
133. Write a Python program to remove multiple spaces from a string.
134. Write a Python program to retrieve the number from the given string
135. Write a python program to work with meta character “.”