File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ #  A program to check whether the string contains equal & same no of characters 
2+ import  collections 
3+ 
4+ 
5+ def  check_strings (word1 , word2 ):
6+     word1  =  list (word1 )
7+     word2  =  list (word2 )
8+     dict1  =  {}
9+     dict2  =  {}
10+     flag  =  True 
11+     for  i  in  word1 :
12+         if  i  in  dict1 :
13+             dict1 [i ] =  dict1 [i ] +  1 
14+             continue 
15+         else :
16+             dict1 [i ] =  1 
17+     for  i  in  word2 :
18+         if  i  in  dict2 :
19+             dict2 [i ] =  dict2 [i ] +  1 
20+             continue 
21+         else :
22+             dict2 [i ] =  1 
23+     if  len (dict1 ) ==  len (dict2 ):
24+         for  k , v  in  dict1 .items ():
25+             if  k  in  dict2 :
26+                 if  dict2 [k ] ==  v :
27+                     continue 
28+                 else :
29+                     flag  =  False 
30+                     break 
31+             else :
32+                 flag  =  False 
33+                 break 
34+     if  flag :
35+         print ("Same" )
36+     else :
37+         print ("Not Same" )
38+ 
39+ 
40+ def  main ():
41+     word1  =  input ("Enter first string : " )
42+     word2  =  input ("Enter second string : " )
43+     check_strings (word1 , word2 )
44+     word  =  "madam" 
45+ 
46+ 
47+ main ()
Original file line number Diff line number Diff line change 1+ # A python program to calculate the frequency of each character in the string 
2+ def  count_frquency (word ):
3+     val = dict ()
4+     word = list (word )
5+     for  i  in  word :
6+         if  i  in  val :
7+             val [i ]= val [i ]+ 1 
8+             continue 
9+         else :
10+             val [i ]= 1 
11+     print (word )
12+     return  val 
13+ 
14+ 
15+ def  main ():
16+     word = input ("Enter a string whose frequency you want to calculate " )
17+     print (word )
18+     print ("Frequency of respective characters in {0} is {1}" .format (word ,count_frquency (word )))
19+ 
20+ main ()
21+ 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments