![Python-courses-python-exercises-games-Python-courses-](https://1.bp.blogspot.com/-T3BongcoJFo/X4CftQxVL8I/AAAAAAAAB5U/Lf59WgNyhGo2FdogKqxv0PIy_Ef7XDPdgCLcBGAsYHQ/s0/my-python-courses-python-exercises-with-solutions.png)
Exercise 68
Write a python algorithm that find the number of common characters in two strings s1 and s2. Example if s = "Hello" and s2 = "World", the shared characters are 'l' and 'o', then the algorithm returns 2.
Solution
s1 = "Hello"
s2 = "World"
# initializing counter
counter = 0
# creating and initializing a string by deleting the repeated characters in s1
s = ""
for x in s1:
if x not in s:
s = s + x
for x in s:
if x in s2:
counter = counter + 1
# display the number of common characters in strings s1 and s2
print(counter) # display 2
Younes Derfoufi
my-courses.net
my-courses.net