Skip to main content

Python 3 functions and Oops -string method / hacker rank

 


def stringmethod(para, special1, special2, list1, strfind):
    
    word1=""
    for letter in para:
        if letter not in special1:
            word1+=letter
    wordn=word1[0:70] 
    rword2=wordn[::-1] 
    print(rword2)
    rword2=rword2.replace(" ","")
    print(special2.join(rword2))
    list3=[]
    if all(SearchStr in para for SearchStr in list1):
        print("Every string in %s were present" %list1)
    else:
        print("Every string in %s were not present" %list1)
            
    new=word1.split()
    print(new[:20])
    lesscount=[]
    emtdis=dict()
    
    for i in new:
        emtdis[i]=emtdis.get(i,0)+1
        for index,ele in emtdis.items():
            if ele<3:
                lesscount.append(index)
            
            
    print(lesscount[-20:])
    print(word1.rfind(strfind))

Comments

Popular posts from this blog

Class and object Task 1| cinema tickets | hacker rank|tcs fresco play

  class   Movie :      def   __init__ ( self , nameofmovie , nooftickets , totalcost ):          self . nameofmovie = nameofmovie          self . nooftickets = nooftickets          self . totalcost = totalcost      def   __str__ ( self ):          return   "Movie : " + str ( self . nameofmovie ) + "\n" + "Number of Tickets : " + str ( self . nooftickets ) + "\n" + "Total Cost : " + str ( self . totalcost )                   # Write your code here if   __name__  ==  '__main__' :

Magic constant generator -python3/hacker rank solution / tcs fresco play

  def   generator_Magic ( n1 ):      # the value starts from 3 and m is formula for constant,      #for generator  yield should use      for   a   in   range ( 3 , n1 + 1 ):          m = a * ( a ** 2 + 1 ) / 2          yield   m               # Write your code here if   __name__  ==  '__main__' :

Handling Exceptions 1 | hacker rank solution

  #!/bin/python3 import   math import   os import   random import   re import   sys # # Complete the 'Handle_Exc1' function below. # # def   Handle_Exc1 ():      a = int ( input ())      b = int ( input ())      if   a > 150   or   b < 100 :          raise   ValueError   ( "Input integers value out of range." )        if   a + b > 400 :          raise   ValueError ( "Their sum is out of range" )      print ( "All in range" )      # Write your code here if   __name__  ==  '__main__' :      try :          Handle_Exc1 ()   ...