当前位置:网站首页>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))边栏推荐
- Arduino - character judgment function
- Go basic data type
- 【Proteus仿真】51单片机+LCD12864推箱子游戏
- [analysis of STL source code] imitation function (to be supplemented)
- RTP 接发ps流工具改进(二)
- ArrayList分析2 :Itr、ListIterator以及SubList中的坑
- Interface switching based on pyqt5 toolbar button -2
- Data set - fault diagnosis: various data and data description of bearings of Western Reserve University
- 67页新型智慧城市整体规划建设方案(附下载)
- All things work together, and I will review oceanbase's practice in government and enterprise industry
猜你喜欢
随机推荐
Mapper agent development
MySQL Foundation
RuntimeError: no valid convolution algorithms available in CuDNN
JDBC教程
返回二叉树中最大的二叉搜索子树的大小
leetcode 650. 2 keys keyboard with only two keys (medium)
Yolox enhanced feature extraction network panet analysis
Go project operation method
Third party payment function test point [Hangzhou multi tester _ Wang Sir] [Hangzhou multi tester]
2022年最新最全软件测试面试题大全
Judge whether the binary tree is full binary tree
[live broadcast appointment] database obcp certification comprehensive upgrade open class
sourcetree 详细
yolov5train. py
How does win11 turn on visual control? Win11 method of turning on visual control
Leetcode relaxation question - day of the week
Writing of head and bottom components of non routing components
Leetcode DP three step problem
leetcode 650. 2 keys keyboard with only two keys (medium)
CADD课程学习(4)-- 获取没有晶体结构的蛋白(SWISS-Model)









