PRP Experiment 5
PRP Experiment 5
Properties of Strings
Example of String
print(text[0]) # H (Indexing)
2 List (list)
Properties of Lists
Example of List
print(my_list[1]) # "apple"
Tuple (tuple)
Properties of Tuples
Example of Tuple
print(my_tuple[1]) # "apple"
String Programs:
#string fundamental
mylist=["Today","is","Monday"]
x=" ".join(mylist)
print(x)
l=len(str)
print("LEngth=",l)
c1=str.count('apple')
print(c1)
c2=str.count('apple')
print(c2)
x2=str.count('a',5)
#string comarision
print("Hello"=="HEllo")
print("Hello"<"HEllo")
print("Hello">"HEllo")
print("Hello"!="HEllo")
#finding index
str2="Hello Friends!!!"
print(str2.find('e'))
print(str2.find('g'))
#partition
s4=str3.partition("deadliest")
print(s4)
s5=str3.partition("Hapiest")
print(s5)
Join function
list1=['1','hi']
str1='#'
str2=str1.join(list1)
print(str2)
str3=str1.join('Hello Friends')
print(str3)
Palindrome
str1=input("enter string:ma")
str2=str1[::-1]
if str1==str2:
print("Palindrome")
else:
print("not palindrome")
Symmetrical
l=int(len(str1)/2)
str2=str1[:l]
str3=str1[l:]
print(str2,str3)
if str2==str3:
print("Symmetrical")
else:
print("non symmetrical")
Even Length
str1=input("Input a sentence:")
l=str1.split(" ")
for i in l:
if len(i)%2==0:
print(i)
String Check
elif alpha:
elif digit:
else:
List Programs
1)Write a python program to print the sum of elements of a list
str= [ 1,2, 5 , 7 , 8 ]
t=0
for i in str:
t=t+i
str= [ 1,2, 5 , 7 , 8 ]
t=1
for i in str:
t=t*i
z= l1[x:y]
z.reverse()
l1[x:y]=z[:]
print(l1)
4)Write a python program to remove the empty string from a list of strings
str= ["hello","","hiii"]
for i in str:
if i=="":
str.remove(i)
print("Result: ",str)
5)Write a python program to find the first non repeated number in a list
l1=[1,2,1,2,3,5,7]
for i in l1:
a=l1.index(i)
if i not in l1[a+1:]:
print(i)
break;
6)Write a python program to find all the pairs from a list whose sum is equal to
given input
l1=[1,7,2,4,3,6,9]
pairs=[]
for i in l1:
x=l1.index(i)
for j in l1[x+1:]:
if i+j==10:
pairs.append((i,j))
print(pairs)
--List comprehension
sentence='Unity Has strenghth'
print("All charachters=",chars)
print("\nvowels=",vowels)
orig_prices=[1.25,-9.45,10.22,3.78,-5.92,1.16]
print(new)
l=[-2,1,2,3,4,5,6,7,8]
s1=[i*i for i in l]
print(s1)
list=['keras','tensorflow','kubernetes']
print(k)
list=['keras','tensorflow','kubernetes']
print(k)
l=['abc','bef','abcd','fegs']
print(new)