-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectword.py
47 lines (38 loc) · 1019 Bytes
/
collectword.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/8/15 21:05
# @Author : xiangxiao
# @FileName: collectwords.py
# @Software: PyCharm for conda3
# @Version: V0.1
aaalist = []
aaa = "jack dog cat monkey dog cat monkey monkey dog boy boy dog lion"
aaalist = aaa.split(" ")
print(aaalist)
bbblist = []
dic1 = {}
dic2 = {}
for i in range(0, len(aaalist)):
count = 1
for j in range(i+1, len(aaalist)):
if ( aaalist[i] == aaalist[j] ):
count += 1
if aaalist[i] not in dic1:
dic1[aaalist[i]] = count
print(dic1.items())
#print(sorted(dic1.values()))
#print(sorted(dic1.values()))
dic2 = sorted(dic1.items(), key=lambda item:item[1])
print(dic2)
for key, value in dic2:
#print(f'{key}:{value}')
if key not in bbblist :
bbblist.append(key)
bbblist.reverse()
print(bbblist)
dic3 = sorted(dic1.items(), key=lambda item:item[1], reverse=True)
print(dic3)
for key, value in dic3:
if key not in bbblist :
bbblist.append(key)
print(bbblist)