## Thursday, October 29, 2020

Solution Exercise 75: Python algorithm to find the list of common characters for a given two strings #### Exercise 75

Write a python algorithm which determines the list of all common characters to two strings s1 and s2 without repetition. Example if s1 = "Python language" and s2 = "Programming", the algorithm returns the liste ['P', 'o', 'n', 'a', 'g'] ( the charcter 'g' must be added only once even if shared twice)

#### Solution

``````def commonCharacters(s1 , s2):
# initializing the list of common characters
listCommon = []
for x in s1:
if x in s2 and x not in listCommon:
listCommon.append(x)
return listCommon

# Example
s1 = "Python language"
s2 = "Programming"
print("List of common characters : ", commonCharacters(s1 , s2))
# The output is : List of common characters :  ['P', 'o', 'n', 'a', 'g']``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 