Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

count matching in two strings

# Python3 code to count number of matching
# characters in a pair of strings
 
# Function to count the matching characters
def count(str1, str2) :
 
    c = 0; j = 0;
 
    # Traverse the string 1 char by char
    for i in range(len(str1)) :
 
        # This will check if str1[i]
        # is present in str2 or not
        # str2.find(str1[i]) returns -1 if not found
        # otherwise it returns the starting occurrence
        # index of that character in str2
        if str1[i] in str2 :
            c += 1;
            #print(str1[i])
        j += 1;
     
    print("No. of matching characters are: ", c );
 
 
# Driver code
if __name__ == "__main__" :
    str1 = "aabcddekll12@";
    str2 = "bb2211@55k";
     
    count(str1, str2);
     
# This code is contributed by AnkitRai01
Comment

PREVIOUS NEXT
Code Example
Python :: godot knockback 
Python :: change bg awesomewm 
Python :: import date formater 
Python :: NumPy bitwise_or Code When inputs are Boolean 
Python :: NumPy right_shift Code When inputs and bit shift are an arrays 
Python :: All possible combinations of multiple columns 
Python :: ROS subscribes to image type video frames (Python) through topic Publishing 
Python :: http://172.18.0.128:8114/ 
Python :: #check if the given date is a weekday or weekend 
Python :: pandas cleaning dataframe regex 
Python :: penggunaan keys di python 
Python :: Creating a Dictionary using built-in function dict() 
Python :: list python !g 
Python :: torch view vs unsqueeze 
Python :: comprehension 
Python :: python turtle star 
Python :: dimensions of dataset in python 
Python :: find sum of all elements in a matrix by python 
Python :: Flask select which form to POST by button click 
Python :: get type of enum variable python 
Python :: EDA dataframe missing and zero values 
Python :: python entry element 
Python :: function to find the mean of column in dataframe in python 
Python :: Hiding and encrypting passwords in Python using advpass() module 
Python :: search for file in a whole system 
Python :: import sys execute cmd 
Python :: python durchschnitt liste 
Python :: how to hash out a big paragraph in vs code python 
Python :: Flask - store object directly in a session [duplicate] 
Python :: python notification image 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =