Saturday, September 12, 2020
Python Challenges Program
Challenges program:
program 1:
#Input :ABAABBCA
#Output: A4B3C1
str1="ABAABBCA"
str2=""
d={}
for x in str1:
d[x]=d.get(x,0)+1
print(d)
for k,v in d.items():
str2+=k+str(v)
print(str2)
Output:
{'A': 4, 'B': 3, 'C': 1}
A4B3C1
program 2:
#Input :a4b3c2
#Output: aaaabbbcc
str1="a4b3c2"
str2=""
for ch in str1:
if ch.isalpha():
x=ch
else:
d=int(ch)
str2=str2+x*d
print(str2)
output:
aaaabbbcc
program 3:
#Reverse the middle words
#Input :Hi how are you python
#Output: Hi woh era uoy python
str1="Hi how are you python"
list1=[x for x in str1.split(" ")]
print(list1[0],end=" ")
for i in range(1,len(list1)-1):
print(list1[i][::-1],end=" ")
print(list1[len(list1)-1])
Output: Hi woh era uoy python
program 4:
#Input :B4A1D3
#Output: ABD134
str1="B4A1D3"
alphabet=[]
digit=[]
for x in str1:
if x.isalpha():
alphabet.append(x)
else:
digit.append(x)
result=(sorted(alphabet)+sorted(digit))
print("".join(result))
Output: ABD134
program 5:
#Input :aaaabbbccz
#Output: 4a3b2c1z
str1="aaaabbbccz"
str2=""
n=len(str1)
previous=str1[0]
count=1
i=1
while i
Subscribe to:
Post Comments (Atom)
Python Challenges Program
Challenges program: program 1: #Input :ABAABBCA #Output: A4B3C1 str1="ABAABBCA" str2="" d={} for x in str1: d[x]=d...
-
Conditional Functions Return Type Name(Signature) Description T if(boolean testCondition, T valueTrue, T valueFalseOrN...
-
PYSPARK Regular Expression Operations read data from hdfs data is unstructured text data we have to clean the data(regular expressio...
No comments:
Post a Comment