Advertisement
gauravssnl

isogram by gauravssnl.py

Feb 24th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. # isogram.py by gauravssnl
  2.  
  3. __author__ = "gauravssnl"
  4.  
  5. def is_isogram( inputStr ) :
  6.    
  7.     # check type of input string first
  8.     if type( inputStr ) == str :
  9.        
  10.         # condition for empty input string
  11.         if inputStr.strip( ) == '' :
  12.             return ( inputStr  ,False )
  13.        
  14.         # input string  is not empty
  15.         else :
  16.            
  17.             # we need to convert all characters of input string  to lower for input like "Ramr" ,"RAma"
  18.             s = inputStr.lower( )
  19.            
  20.             # check count of each character in input string
  21.             # if it is more than 1 ,then input string s is not isogram
  22.             for i in s :
  23.                 if s.count ( i ) > 1 :
  24.                     return ( inputStr , False )
  25.                
  26.             # thus input string s  is isogram    
  27.             return ( inputStr , True )    
  28.                
  29.                
  30.     else :
  31.         raise AttributeError
  32.  
  33.  
  34. if __name__ ==  '__main__' :
  35.     print( is_isogram( "abolishment") )
  36.     print ( is_isogram( "happy" ) )
  37.    
  38.     # special case where same capital and small letters are present : string is not isogram
  39.     print ( is_isogram( 'Ramr' )  )
  40.    
  41.     # print ( is_isogram( 105 )  )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement