-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask4.py
60 lines (48 loc) · 1.69 KB
/
Task4.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
53
54
55
56
57
58
59
"""
Read file into texts and calls.
It's ok if you don't understand how to read files
You will learn more about reading files in future lesson
"""
import csv
with open('texts.csv', 'r') as f:
reader = csv.reader(f)
texts = list(reader)
with open('calls.csv', 'r') as f:
reader = csv.reader(f)
calls = list(reader)
# 参考https://github.com/dontlaike/work_uda/blob/a35dc313099e700873ea36d0d9f50654e5dc4f1d/Task4.py
#step1:find no-repeated call when make and receive.
"""
calls_no_repeat_1:make no-repeated outcalling calls
calls_no_repeat_2:received no -repeated calls which has two characteris:
never send texts,receive texts
"""
calls_no_repeat_1 = []
calls_no_repeat_2 = []
for call in calls:
if call[0] not in calls_no_repeat_1:
calls_no_repeat_1.append(call[0])
if call[1] not in calls_no_repeat_2:
calls_no_repeat_2.append(call[1])
for text in texts:#add telephone# which send and receive texts
if text[0] not in calls_no_repeat_2:
calls_no_repeat_2.append(text[0])
if text[1] not in calls_no_repeat_2:
calls_no_repeat_2.append(text[1])
#step2:find the exclused telephone#
telemarketers = list(set(calls_no_repeat_1).difference(set(calls_no_repeat_2)))
telemarketers.sort()
print("These numbers could be telemarketers:")
for i in telemarketers:
print('\n'+i)
"""
TASK 4:
The telephone company want to identify numbers that might be doing
telephone marketing. Create a set of possible telemarketers:
these are numbers that make outgoing calls but never send texts,
receive texts or receive incoming calls.
Print a message:
"These numbers could be telemarketers: "
<list of numbers>
The list of numbers should be print out one per line in lexicographic order with no duplicates.
"""