Type Here to Get Search Results !

codemind python strings

Note: click on newest button on top select old


CAMEL CASE WORD COUNT


a=input()

count=0

for i in a:

    if ord(i)<91:

        count+=1

if ord(a[0])>94:

    count+=1

print(count)



COUNT NO. OF VOWELS ,CONSONANTS ,DIGITS AND SPACES


a=list(input())

vowel=const=space=digit=0

for i in a:

    if i in ['a','e','i','o','u','A','E','I','O','U']:

        vowel+=1

    elif i in ['1','2','3','4','5','6','7','8','9','0']:

        digit+=1

    elif i in ' ':

        space+=1

    else:

        const+=1

print('Vowels:',vowel)

print('Consonants:',const)

print('Digits:',digit)

print('White spaces:',space)



COUNT NO.OF WORDS


a=input()

print(a.count(' ')+1)



COUNTING THE OCCURANCES


a=input()

b=input()

c=a.count(b)

if c:

    print(c)

else:

    print(-1)



Little_Monk_and_Good_String


s=input()
c=0
c1=0
v='aeiou'
for i in range(len(s)):
    if s[i]=='a' or s[i]=='e' or s[i]=='o' or s[i]=='u' or s[i]=='i':
        c+=1
    else:
        if c1<c:
            c1=c
        c=0
if c1<c:
    c1=c
print(c1)


NUMBERS IN STRING


a=input()

count=0

for i in a:

    if i in '1234567890':

        count+=int(i)

print(count)



MAX OF STRING


a=input()

print(max(a))



STRING CONCAT


a=input()

b=input()

c=a+b

print(''.join(sorted(c)))



STRING CONTAIN DIGIT OR NOT


a=input()

count=0

for i in a:

    if i.isdigit():

        count+=1

if(count):

    print('Contains',count,'digit')

else:

    print('Doesn\'t contain digit')



MONK TEACHES PALINDROME


t=int(input())

for i in range(t):

    s=input()

    if s!=s[::-1]:

        print('NO')

    elif(len(s)%2==0):

        print('YES EVEN')

    else:

        print('YES ODD')



STRING CONTAINS DIGITS OR NOT 


t=int(input())

for i in range(t):

    a=input()

    for j in a:

        if j.isdigit():

            print('Yes')

            break

    else:

        print('No')



TO LOWER


a=input()

print(a.lower()



ROBOT RETURN TO ORIGIN


a=input()

x=y=0

for i in a:

    if i is 'L':

        x-=1

    elif i is 'R':

        x+=1

    elif i is 'U':

        y+=1

    else:

        y-=1

print(x==0 and y==0)



REVERSE WORDS IN A STRING III


l=input().split(' ')

l2=[]

for i in l:

    l2.append(i[::-1])

print(' '.join(l2))



Consecutive_Characters


s=input()
c=0
c1=0
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        c+=1
    else:
        if c1<c:
            c1=c
        c=0
if c1<c:
    c1=c
print(c1+1)



Decrypt_String_from_Alphabet_to_Integer_Mapping


class Solution(object):
   def freqAlphabets(self, s):
      m = {}
      x = 'a'
      for i in range(1, 27):
         m[str(i)] = x
         x = chr(ord(x) + 1)
      ans = ""
      m['']=''
      i = len(s) - 1
      while i >= 0:
         if s[i] == "#":
            temp = ""
            for j in range(i - 2, i):
               temp += s[j]
            ans = m[str(temp)] + ans
            i -= 3
         else:
            ans = m[s[i]] + ans
            i -= 1
      return ans
ob1 = Solution()
print(ob1.freqAlphabets(input()))



Maximum_Number_of_Balloons


s=input()
b=0
a=0
l=0
o=0
n=0
for i in s:
    if i=='b':
        b+=1
    if i=='a':
        a+=1
    if i=='l':
        l+=1
    if i=='o':
        o+=1
    if i=='n':
        n+=1
san=0
while b>0 and a>0 and l>0 and o>0 and n>0:
    b-=1
    a-=1
    l-=2
    if l<0:
        break
    o-=2
    if o<0:
        break
    n-=1
    san+=1
print(san)


REVERSE STRING


a=input()

print(a[::-1])



DEFANGING AN IP ADDRESS


a=input()

print(a.replace('.','[.]'))



GOAT LATIN


a=list(map(list,input().split()))

for i in range(len(a)):

    if a[i][0] in ['a','e','i','o','u','A','E','I','O','U']:

        a[i].append('ma')

    else:

        t=a[i][0]

        a[i].pop(0)

        a[i].append(t)

        a[i].append('ma')

    a[i].append('a'*(i+1))

for i in range(len(a)):

    b="".join(a[i])

    print(b,end=" ")



Roman_to_Integer


def value(r):
    if (r=='I'):
        return 1
    if (r=='V'):
        return 5
    if (r=='X'):
        return 10
    if (r=='L'):
        return 50
    if (r=='C'):
        return 100
    if (r=='D'):
        return 500
    if (r=='M'):
        return 1000
    return -1
 
def roman(str):
    res=0
    i=0
    while(i<len(str)):
        s1=value(str[i])
        if (i+1<len(str)):
            s2=value(str[i+1])
            if (s1>=s2):
                res=res+s1
                i=i+1
            else:
                res=res+s2-s1
                i=i+2
        else:
            res=res+s1
            i=i+1
    return res
n=input()
print(roman(n))


RANSOM NOTE


def num(x,y):

    for i in x:

        if i in y:

            y.remove(i)

        else:

            return False

    return True

x,y=map(list,input().split())

print(num(x,y))



FIRST UNIQUE CHARACTER IN A STRING


a=input()

for i in a:

    j=a.index(i)

    if i not in a[j+1:]:

        print(j)

        break

else:

    print(-1)



Checking_valid_parenthesis_or_Not


s=input()
n=len(s)
if s[0]=='(' and s[n-1]==')':
    print('True')
else:
    print('False')


MULTIPLY STRINGS


a,b=map(int,input().split())

print(a*b)



DI_String_Match


s=input()
i=0
j=len(s)
for k in s:
    if k=='I':
        print(i,end=' ')
        i+=1
    if k=='D':
        print(j,end=' ')
        j-=1
print(i)


HELLO


a=input()

print('Hello Technicalhub')

print(a)



EXACT SLICE OF STRING 


a=input()

b=int(input())

c=int(input())

print(a[b:c+1])



STRING DECIMAL


t=int(input())

for i in range(t):

    a=input()

    print(a.isnumeric())



Alice_and_Strings

n=int(input())
for k in range(n):
    str1, str2 = input(),input()
    if (len(str1)==len(str2)):
        for i in range(len(str1)):
            if (str1[i]>str2[i]):
                print('NO')
                break
        else:
                print('YES')
    else:
          print('NO')


STRING REVERSE


a=input().split()

print(' '.join(a[::-1]))



Split_houses


n = int(input())
s = input()
c = []
temp = 0
arr = ['']*n
for i,j in enumerate(s):
    if j == 'H':
        arr[i] = 'H'
        temp += 1 
        if i == n-1:
            c.append(temp)
    else:
        arr[i] = 'B'
        if temp > 0:
            c.append(temp)
            temp = 0

if len(c) == 0 or max(c) == 1:
    print('YES')
    print(''.join(arr))
else:
    print('NO')


ZOO


from collections import Counter

a=list(input())

b=dict(Counter(a))

x=b.get('z')

y=b.get('o')

if 2*x==y:

    print('Yes')

else:

    print('No')



FIRST NON REPEATED CHARACTER


t=int(input())

for i in range(t):

    a=int(input())

    s=input()

    for i in s:

        if i not in s[s.index(i)+1:]:

            print(i)

            break

    else:

        print(-1)



Deletion_of_Consecutive_Duplicate_Characters


x=int(input())
for i in range(x):
    s=input()
    n=len(s)
    c=0
    for j in range(len(s)-1):
        if s[j]==s[j+1]:
            c+=1
    print(c)


PROGRAM TO FIND SUM OF ALL NUMBERS PRESENT IN THE STRING 


a=input()

sum=0

for i in a:

    if i in '123456789':

        sum+=int(i)

print(sum)



Program_to_find_the_longest_substring_length_that_contains_(a,_e,_i,_o,_u)_only

s=input()
c=0
c1=0
v='aeiou'
for i in s:
    if i in v:
        c+=1
    if i not in v:
        if c>c1:
            c1=c
        c=0
if c>c1:
    c1=c
print(c1)


PRINT ALL PERMUTATIONS OF STRING 


from itertools import permutations as p

a=input()

l=p(a)

for i in l:

    print(''.join(i))



Evaluate_the_Expression(Calculator)

import math
s=str(input())
print(eval(s))



Flip_and_Win

n=int(input())
s=input()
a=0
i=0
while i<n-1:
    a+=abs(int(s[i+1])-int(s[i]))
    i+=1
a=n-a-1
if(a%3==0):
    print('Sudhir')
else:
    print('Ashok')



Special_string_reverse


s=input()
l=list(s)
alp=[]
spe=[]
spei=[]
for i in range(len(l)):
    if l[i].isalpha():
        alp.append(l[i])
    else:
        spe.append(l[i])
        spei.append(i)
rev=alp[::-1]
for i in range((len(spei))):
    rev.insert(spei[i],spe[i])
print(*rev,sep='')



Even_String_Number


from itertools import *
x = input()
b=[]
e=[]
c=0
for i in x:
    if i.isdigit():
        b.append(int(i))
        c=1
b = sorted(set(b),key=b.index)
b = sorted(b,reverse=True)
for i in b:
    if i%2==0:
        e.append(i)
if c==0:
    print('-1')
elif e==[]:
    print('-1')
else:
    l = min(e)
    for i in range(len(b)):
        if b[i]==l:
            m=i
    b[len(b)-1],b[m]=b[m],b[len(b)-1]
    for i in b:
        print(i,end="")



Password_Generator


s=input()
a1=list(s.split(","))
for i in a1:
    a2=list(i.split(":"))
    n1=a2[0]
    n2=a2[1]
    m='0'
    for i in n2:
        if ord(i)>ord(m):
            if ord(i)-48<=len(n1):
                m=i
    ind=ord(m)-48
    name10=n1*10
    if m=='0':
        print("X",end="")
    else:
        print(name10[ind-1],end="")



Parenthesis_Matching


s=input()
l=[]
f=1
for i in range(len(s)):
    if s[i] in '({[':
        l.append(s[i])
        f=1
    else:
        if len(l)>0:
            if l[-1]=='(' and s[i]==')':
                l.pop()
            elif l[-1]=='{' and s[i]=='}':
                l.pop()
            elif l[-1]=='[' and s[i]==']':
                l.pop()
            else:
                print(i+1)
                f=0
                break
        else:
            print(i+1)
            f=0
            break
if f==1:
    if(len(l)==0):
        print(0)
    else:
        print(len(s)+1)


String_Repetition


s=input()
n=int(input())
le=len(s)
c1,c3=0,0
for i in s:
    if i=='a':
        c1+=1
l=n//le
k=n%le
c3=l*c1
for i in range(k):
    if s[i]=='a':
        c3+=1
print(c3)
Tags