-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex4-2.py
More file actions
32 lines (25 loc) · 706 Bytes
/
Copy pathex4-2.py
File metadata and controls
32 lines (25 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
__author__ = 'Administrator'
def common_chars(s1, s2):
'''(str, str) -> str
Return a new string containing all characters from s1 that appear at least
once in s2. The characters in the result will appear in the same order as
they appear in s1.
>>> common_chars('abc', 'ad')
'a'
>>> common_chars('a', 'a')
'a'
>>> common_chars('abb', 'ab')
'abb'
>>> common_chars('abracadabra', 'ra')
'araaara'
'''
res = ''
# BODY MISSING
for ch in s1:
if ch in s2:
res = res + ch
return res
print(common_chars('abc', 'ad'))
print(common_chars('a', 'a'))
print(common_chars('abb', 'ab'))
print(common_chars('abracadabra', 'ra'))