2332988 BTAIML503-20
Program 25 : Check if a Substring is Present in a given String
Code:
sentence = "Coding in Python is fun and creative"
sub = "Python"
if sub in sentence:
print("Substring is present!")
else:
print("Substring is not present.")
Output:
2332988 BTAIML503-20
Program 26: Program to find even length words in a string .
Code:
sentence = "Python makes coding fun and creative"
words = [Link]()
for word in words:
if len(word) % 2 == 0:
print(word)
Output:
2332988 BTAIML503-20
Program 27: Program to swap all dots and commas in a string .
Code:
sentence = "Hello, world. Python, is fun."
sentence = [Link](",", "#")
sentence = [Link](".", ",")
sentence = [Link]("#", ".")
print("Swapped string:", sentence)
Output:
2332988 BTAIML503-20
Program 28: Given a string “F.R.I.E.N.D.S” , change the string to “friends” .
Code:
title = "F.R.I.E.N.D.S"
result = [Link](".", "").lower()
print(result)
Output:
2332988 BTAIML503-20
Program 29: Extract digit string from a given string .
Code:
sentence = "My ID is 1234 and phone is 98765"
digits = ""
for c in sentence:
if c >= '0' and c <= '9':
digits += c
print(digits)
Output:
2332988 BTAIML503-20
Program 30: Program for Insertion in a list before any element
Code:
colors = ["red", "green", "blue", "yellow"]
new_color = "orange"
index = [Link]("blue")
[Link](index, new_color)
print(colors)
Output:
2332988 BTAIML503-20
Program 31: Write a Program to remove all duplicates from a list .
Code:
numbers = [1, 2, 2, 3, 4, 4, 5]
unique_numbers = []
for num in numbers:
if num not in unique_numbers:
unique_numbers.append(num)
print("List without duplicates:", unique_numbers)
Output:
2332988 BTAIML503-20
Program 32 : WAP that creates a list ‘L’ of 10 random integers. Then create
ODD and EVEN lists containing odd and even values respectively from ‘L’
Code:
L = [12, 7, 45, 22, 9, 30, 18, 3, 50, 27]
EVEN = []
ODD = []
i=0
while i < 10:
if L[i] % 2 == 0:
EVEN += [L[i]] # Concatenating single-element list
else:
ODD += [L[i]]
i += 1
print("Original List:", L)
print("Even Numbers:", EVEN)
print("Odd Numbers:", ODD)
Output:
2332988 BTAIML503-20
Program 33: Write a program to delete all consonents from string"hello cse
python"and create a new string'''
Code:
s = "hello cse python"
v = "aeiou "
new = ""
for c in s:
if c in v:
new += c
print(new)
Output:
2332988 BTAIML503-20
Program 34: Write a program that takes your full name as input and displays
the abbreviations of the first and middle names except the last name which is
displayed as it is. For example, if your name is Robin Ramesh Kumar, then the
output should be [Link].
Code:
name = input("Enter your full name: ")
parts = [Link]()
abbr = ""
for i in range(len(parts) - 1):
abbr += parts[i][0].upper() + "."
abbr += parts[-1]
print("Abbreviated name:", abbr)
Output: