-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhichAreIn.py
37 lines (24 loc) · 1.01 KB
/
WhichAreIn.py
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
33
34
35
36
37
'''
Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.
#Example 1: a1 = ["arp", "live", "strong"]
a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
returns ["arp", "live", "strong"]
#Example 2: a1 = ["tarp", "mice", "bull"]
a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
returns []
Notes:
Arrays are written in "general" notation. See "Your Test Cases" for examples in your language.
In Shell bash a1 and a2 are strings. The return is a string where words are separated by commas.
Beware: r must be without duplicates.
Don't mutate the inputs.
'''
def in_array(array1, array2):
result = []
for i in array1:
for j in array2:
if i in j:
if i not in result:
result.append(i)
result.sort()
return result
print(in_array(["live", "arp", "strong"],["lively", "alive", "harp", "armstrong","sharp"]))