-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprefix_phone.py
53 lines (34 loc) · 1.14 KB
/
prefix_phone.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 8 20:12:06 2019
@author: bijayamanandhar
"""
#Prefix phone
"""
Given:
-A list of prefixes for discount on phone calls
-A list of phone numbers
-Select the prefix phones and form a list as result
"""
#prefixes and numbers both are lists(array)
def prefix_phone(prefixes, numbers):
#empty array for result
selected = []
#iterates thru prefix list
for prefix in prefixes:
#checks number to match prefix
for number in numbers:
#search for prefix in number
if prefix == number[:len(prefix)]:
#adds number to array if matches
selected.append(number)
return selected
prefixes = ['+1234', '+5678', '+3215', '+987']
numbers = ['+9872349871', '+9871234665432', '+8712345671',
'+32159865342', '45452677721', '+5678111222333',
'+8362412300', '+82726241611']
expected = ['+5678111222333', '+32159865342',
'+9872349871', '+9871234665432']
print(prefix_phone(prefixes, numbers) == expected) # True
#End of file