当前位置:网站首页>Unique line of "Gelu"
Unique line of "Gelu"
2022-07-02 23:47:00 【Sweet cake】
These two days “ grue ” The word frequency is hot , You know what is “ grue ” Do you ?
Gelu sound comes from northeast dialect ( It's actually Shandong dialect ), For daily life , Very different , The number of ways is not popular . To put it bluntly , Just a little maverick , unique .
ha-ha , Don't say , It's also in the file “ grue ” Of , That is the unique line , Is a line different from any other line . They are silently mixed in repeated lines , There are no two brushes , It is difficult for you to quickly determine how many unique lines there are in a file .
Python Sure .
Ideas :
- Files are generally composed of unique lines and repeated lines , either this or that .
- aggregate The de duplication characteristic of
- list Removal function of
Code :
f = open('file') # ① Open the target file
ls = f.readlines() # ② Read the behavior list
s1 = set(ls) # ③ Convert list to set , The element is represented by repeating lines + Unique line
for i in s1: # ④ Remove the rows after de duplication from the list one by one
ls.remove(i)
s2 = set(ls) # ⑤ The list after transfer division is set , The element is represented by repeating lines
print(' This article has {} Unique line '.format(len(s1)-len(s2)))
Can also be based on Dictionaries Characteristics , Using the traversal method , With action key , The statistical corresponding value is 1 The line of :
f = open('file')
d = {}
for i in f:
d[i] = d.get(i, 0) + 1
count = 0
for k in d.keys():
if d[k] == 1:
count += 1
print(' This article has {} Unique line '.format(count))
边栏推荐
- Request and response
- Program analysis and Optimization - 9 appendix XLA buffer assignment
- Codeforces Round #771 (Div. 2)---A-D
- Sourcetree details
- How to set automatic reply for mailbox and enterprise mailbox?
- Which common ports should the server open
- 流媒体技术优化
- Why can't the start method be called repeatedly? But the run method can?
- Interface switching based on pyqt5 toolbar button -2
- Fusion de la conversion et de la normalisation des lots
猜你喜欢
How to apply for company email when registering in company email format?
What if win11 can't turn off the sticky key? The sticky key is cancelled but it doesn't work. How to solve it
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
YOLOX加强特征提取网络Panet分析
Ideal car × Oceanbase: when the new forces of car building meet the new forces of database
Flexible combination of applications is a false proposition that has existed for 40 years
Mapper agent development
Interface switching based on pyqt5 toolbar button -2
How does win11 turn on visual control? Win11 method of turning on visual control
面试过了,起薪16k
随机推荐
Go basic constant definition and use
公司里只有一个测试是什么体验?听听他们怎么说吧
95页智慧教育解决方案2022
采用VNC Viewer方式遠程連接樹莓派
理想汽车×OceanBase:当造车新势力遇上数据库新势力
Yolox enhanced feature extraction network panet analysis
附加:token;(没写完,别看…)
【OJ】两个数组的交集(set、哈希映射 ...)
sourcetree 详细
JSON数据传递参数
C# MVC创建一个视图摆脱布局的影响
Markdown basic grammar
RTP 接发ps流工具改进(二)
第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】
95 pages of smart education solutions 2022
Request and response
接口差异测试——Diffy工具
基于Pyqt5工具栏按钮可实现界面切换-1
【ML】李宏毅三:梯度下降&分类(高斯分布)
[live broadcast appointment] database obcp certification comprehensive upgrade open class