line

统计文件中单词出现频率最高的10个以及他们出现的次数

空扰寡人 提交于 2020-01-17 12:13:44
import re regex = "[a-zA-Z]+" with open("./test.py") as f: lines = f.readlines() worddict = dict() for line in lines: words = re.findall(regex, line) for word in words: if word in worddict.keys(): worddict[word] += 1 else: worddict[word] = 1 words_top10 = sorted(worddict.items(), key=lambda x: x[1], reverse=True) print(words_top10) 来源: https://www.cnblogs.com/zhengze/p/12204612.html

两个有用的shell工具总结

六眼飞鱼酱① 提交于 2020-01-17 07:11:24
shell工具之一:sed sed基础 sed编辑器被称作流编辑器,与常见的交互式文本编辑器刚好相反。文本编辑器可以通过键盘来交互式地插入、删除、替换文本中的数据;而流编辑器是基于一组预先的规则来编辑数据流。 sed命令的格式如下: sed options script file 选项 说明 -e script 将script中指定的命令添加到运行的命令中 -f file 将file中指定的命令添加到运行的命令中 -n 不为每个命令生成输出,等待print命令来输出 说明: script用于指定作用在数据量上的单个命令。 如果需要使用多个命令,有 两种选择 :可以在命令行中使用-e选项指定,不同命令之间用分号隔开;或者使用-f选项在文件中指定。 默认情况下,sed编辑器将指定的命令应用到STDIN输入流上,而不作用于数据源本身,就是说sed不会修改文本文件中的原数据。 1 替换命令substitute s/pattern/replacement/flags flags 取值如下: 数字: 表示replacement将替换 每行中 第几次出现的pattern g : 表示replacement将替换所有出现的pattern p : 打印用replacement替换过的行(经常与-n选项搭配使用,-n禁止sed输出,而p会输出修改过的行

[shell编程]初识sed和gawk

我怕爱的太早我们不能终老 提交于 2020-01-17 07:01:53
一.sed编辑器 shell脚本最常见的用途就是处理文本文件,sed和gawk能够极大的简化需要进行的数据处理任务。 sed编辑器是流编辑器,跟普通交互式文本编辑器(如vim)不同。流编辑器在编辑器处理数据前基于预先提供的一组规则来编辑数据流。由于命令都是一行一行顺序处理,sed编辑器必须一次就完成对文本的修改,所以比交互式编辑器速度快很多。 使用sed命令的格式:$ sed optioons script file 1.替换标记 s命令帮助我们用斜线间制定的第二个文本字符串代替地一个文本字符串,举一个简单的例子: # echo This is a dog | sed 's/dog/big dog/' This is a big dog 在sed命令行上执行多个命令时,用-e选项: # echo This is a white dog | sed -e 's/white/black/; s/dog/cat/' This is a black cat 如果有大量sed命令,可以放入一个文件内,用-f选项制定文件,此时不需要用分号: $ cat script s/white/black s/dog/cat 2.使用地址 默认情况下,sed编辑器中使用的命令会作用与文本数据的所有行。如果只想将命令作用于特定某行或者某些行,需要用 行寻址 。 sed有两种行寻址:行的数字范围

Line Segments Intersection(intersection Point)

删除回忆录丶 提交于 2020-01-17 02:57:30
问题 I have created a function to calculate the intersection point of two line segment . Unfortunantly the code below dosen't work if one of the segment is verticale public static Point intersection(Segment s1, Segment s2) { double x1 = s1.getP1().getX(); double y1 = s1.getP1().getY() ; double x2 = s1.getP2().getX(); double y2 = s1.getP2().getY() ; double x3 = s2.getP1().getX(); double y3 = s2.getP1().getY(); double x4 = s2.getP2().getX(); double y4 = s2.getP2().getY(); double d = (x1 - x2) * (y3

python Django 报错 SyntaxError: Generator expression must be parenthesized 解决方法

∥☆過路亽.° 提交于 2020-01-16 18:40:25
Django 报错 SyntaxError: Generator expression must be parenthesized Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "D:\lijingwen\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line utility.execute() File "D:\lijingwen\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 338, in execute django.setup() File "D:\lijingwen\Python\Python37\lib\site-packages\django\__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "D:\lijingwen

How can I save lines with spaces between characters in the right way (Array)?

自古美人都是妖i 提交于 2020-01-16 18:22:12
问题 Two examples of Lines: Bob 02 02 10 80 Enquiries Martin Corp 02 02 10 80 Langar Note, that the first line doesn't have an information after "Bob", so just spaces. So my code would be: $account_name = $inputFileContent[$i].Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries) Edit: My output-array should be like: $account_name = Bob (Empty Line) 02 02 10 80 Enquiries Is there a way to change the code, so I have it saved in a array in that format? 回答1: One possibility is to use regular

pandas相关报错:pandas/_libs/hashtable_class_helper.pxi...

吃可爱长大的小学妹 提交于 2020-01-16 05:27:58
问题记录 return self._engine.get_loc(key) File "pandas/_libs/index.pyx", line 107, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/index.pyx", line 131, in pandas._libs.index.IndexEngine.get_loc File "pandas/_libs/hashtable_class_helper.pxi", line 1607, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas/_libs/hashtable_class_helper.pxi", line 1614, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 0 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:/python_workspace/Air/renew.py", line 106, in

使用python发邮件

狂风中的少年 提交于 2020-01-16 00:19:08
import smtplib from email . mime . text import MIMEText from email . header import Header from email . mime . multipart import MIMEMultipart from email . utils import formataddr import argparse import os import re import subprocess def run ( cnv_vcf , purity , prefix ) : infile = open ( cnv_vcf , "r" ) outfile = open ( "%s.final.CNV.tsv" % ( prefix ) , "w" ) outfile . write ( "#Chr\tStart\tend\tRef\tType\tGene\tCopyNumber\n" ) num = 0 for line in infile : line = line . strip ( ) if not line . startswith ( "#" ) : array = line . split ( "\t" ) if array [ 4 ] == "<DUP>" or array [ 4 ] == "<DEL>"

maskrcnn-benchmark安装及常见错误

馋奶兔 提交于 2020-01-15 21:06:27
Mask rcnn环境配置  在安装好Anaconda之后可以配置Mask RCNN了。这里我用的是maskrcnn-benchmark,环境搭建相对简单。 1. 创建虚拟环境: source activate conda create -n MaskRCNN python=3 conda activate MaskRCNN 完成后,可看到如下界面: 2. 安装各种依赖包: conda install ipython pip install ninja yacs cython matplotlib tqdm opencv-python 3. 安装PyTorch    PyTorch官网 ,根据自己的电脑配置选择,会出现对应命令。 conda install pytorch torchvision cudatoolkit=10.0 -c pytorch   这里可以测试一下torchvision是否安装成功。如果没有安装成功,则需要下载源码编译安装(别着急,后面有写)。 :~$ python >>>>import torch >>>>import torchvision    4. 安装目录 export INSTALL_DIR=/data_1/software/pytorch/MaskRCNN  //设置自己的安装目录 cd $INSTALL_DIR    5.

记录cobbler报错

烈酒焚心 提交于 2020-01-15 20:37:14
出现下面这个错误解决方法 httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback: Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/cobbler/cli.py", line 251, in check_setup s.ping() File "/usr/lib64/python2.7/xmlrpclib.py", line 1233, in __call__ return self.__send(self.__name, args) File "/usr/lib64/python2.7/xmlrpclib.py", line 1591, in __request verbose=self.__verbose File "/usr/lib64/python2.7/xmlrpclib.py", line 1273, in request return self.single_request(host, handler, request_body, verbose) File "/usr/lib64/python2.7/xmlrpclib