# -*- coding: utf-8 -*- #spyder (python 3.7) 1. 统计字符(可以在jieba分词之后使用) from collections import Counter from operator import itemgetter # txt_list可以写成函数参数进行导入 txt_list = ['千古','人间','人间','龙','龙','龙','哈哈哈','人才','千古','千古'] c = Counter() for x in txt_list:…
python统计元素重复次数 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- from collections import Counter arr = ['BAISC', 'Python', 'BASICA', 'GVBASIC', 'GWBASIC', 'Python', 'ETBASIC', 'QBASIC', 'Quick', 'Basic', 'Turbo', 'Basic'] counts = list(Counter(arr).items…
#use python3.6 import re from collections import Counter FILESOURCE = './abc.txt' def getMostCommonWord(artlclefilesource): pattern = r"""[A-Za-z]+|\$?\d+%?$""" with open(artlclefilesource) as f: r = re.findall(pattern,f.read…
解析 robots.txt 文件 使用的系统:Windows 10 64位 Python 语言版本:Python 2.7.10 V 使用的编程 Python 的集成开发环境:PyCharm 2016 04 我使用的 urllib 的版本:urllib2 注意: 我没这里使用的是 Python2 ,而不是Python3 一 . 前言 之前,我在网络爬虫科普的时候,介绍过robots.txt 文件,如果你还了解这个文件的功能,请到这个博客学习. 有一些站点它在 robots.txt 文件中设定了禁止…
以下将会通过JS循环判断字符“banana”出现次数 以及调用indexOf中的函数来实现统计   <!DOCTYPE html> <html> <body> <p id="p1">apple banana orange banana apple orange banana</p> <button onclick="myFunction()">Try it</button> <…
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" con…
var s = "The rain in Spain falls rain mainly in the rain plain"; var reg = new RegExp("rain", "g"); alert(s.match(reg).length);…
''' 模块和包管理 模块和包的定义: 模块:模块是一个Python文件,以.py结尾,包含了Python对象定义和Python语句 包:Python中的包就是一个包含__init__.py文件的目录(文件夹) 为什么代码会有浅色的波浪线和红色的波浪线? 浅色的波浪线:pycharm检测你的这行代码不符合pep8规范(官方给出的编码规范) 红色的波浪线:pycharm检测到这行代码语法有问题,或者变量找不到(没有被定义) 模块的作用: 模块让你能够有逻辑地组织你的Python代码段 把相关的功能…
原文地址:https://blog.csdn.net/weixin_42555131/article/details/82012642 生成txt文件: mesg = "hello world" with open("test.txt", "w") as f: f.write("{}".format(mesg)) print("加载完成!") 生成json文件: import json mesg = {&q…
import os def new_txt(): a1='实线' b = os.getcwd() + '\\fazhandadao_test_txt\\' if not os.path.exists(b): os.makedirs(b) for file in range(1000,1020): open(b+a1+str(file)+'.txt', "w") if __name__ == '__main__': new_txt()…