PHP 除去重复笔记

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
#
# par_names_numbers_.py
#
 
def remove_repeats(list):
    """returns a list without repeats"""
    new_list = []
    for i in list:
        if i not in new_list:
            new_list += [i]
    return new_list
     
 
first_names_file = open(‘feb_new_member_first_names.txt‘, ‘r‘)
text = first_names_file.read()
firsts_list = text.split(‘\n‘)
first_names_file.close()
 
last_names_file = open(‘feb_new_members_last_names.txt‘, ‘r‘)
text = last_names_file.read()
lasts_list = text.split(‘\n‘)
 
phones_file = open(‘feb_new_members_phones.txt‘, ‘r‘)
text = phones_file.read()
phones_list = text.split(‘\n‘)
 
new_lasts = remove_repeats(lasts_list)
print len(new_lasts)
new_phones = remove_repeats(phones_list)
print len(new_phones)
 
last2phone = {}
first2last = {}
 
for i in range(len(lasts_list)):
    last2phone[lasts_list[i]] = phones_list[i]
    first2last[firsts_list[i]] = lasts_list[i]
         
output_file = open(‘feb_members_to_call.txt‘, ‘w‘)
output_file.write("%-18s%-18s%-s" % (‘first name‘, ‘last name‘, ‘phone number‘))
output_file.write(‘\n‘ + ‘=‘*49)
for key in last2phone.keys():
    output_file.write("\n" + "%-18s%-18s%-s" % (first2last[key], key, last2phone[key]))
output_file.close()

  注释:在英文外链操作中,可用此段代码进行操作.

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。