Python Programming Questions - Operation on STRING[SET-4]
1. Python Program To Swap commas and dots in a String
inputString = input(" Enter The String : ")
print(" Before Swapping : ",inputString)
inputString = inputString.replace(',','symbol')
inputString = inputString.replace('.',',')
inputString = inputString.replace('symbol','.')
print(" After Swapping : ",inputString)
Enter The String : COMPTER,,SCIENCE..IS,,FUN..
Before Swapping : COMPTER,,SCIENCE..IS,,FUN..
After Swapping : COMPTER..SCIENCE,,IS..FUN,,
2. Python program for permutation of a given string using inbuilt function
from itertools import permutations
inputString = input(" Enter The String : ")
permutate = permutations(inputString)
permutateList = list(permutate)
counter = 0
for words in permutateList:
print(''.join(words))
counter = counter + 1
print(" Total Word Formed : ",counter)
Enter The String : TCS
TCS
TSC
CTS
CST
STC
SCT
Total Word Formed : 6
Comments
Post a Comment