参考:获取python的list中含有重复值的index方法_python_脚本之家 核心思想:建立字典,遍历列表,把列表中每个元素和其索引添加到字典里面 cc = [1, 2, 3, 2, 4] from collections import defaultdict dd = defaultdict(list) for k, va in [(v,i) for i, v in enumerate(cc)]: dd[k].append(va) print(dd) output: defaultdi
实际上是这样,将获取到网页中表单内容与汉字字符串作比较,即: a = request.POST['a'] if a == '博客园': print 'ok' else: print 'false' a是表单内容,假设为"博客园",内容输出理论上为ok,但为false,这是为什么了,带着疑问,百度了一下,发现是python编码的问题,代码改成这样就解决了: a = request.POST['a'] if a == u'博客园': print 'ok' else: print 'fals
# -*- coding: utf-8 -*- import urllib2 import re import time import jieba url="http://www.baidu.com" html=urllib2.urlopen(url).read() html=unicode(html,'utf-8') word=re.findall(ur"[\u4e00-\u9fa5]+",html) s="" for w in word: s
from:http://stackoverflow.com/questions/699468/python-html-sanitizer-scrubber-filter 通过下面这个代码就可以把内容过滤成干净的HTML内容,说明,这个代码来自上面Stackoverflow的回答 Use lxml.html.clean! It's VERY easy! from lxml.html.clean import clean_html print clean_html(html) <html> <
1, 使用文件 #vim /etc/motd "1 hello world" 2 ...... yes 3 no you are a shadiao 4 hahh maye you are right ddddddddddddddddddddddddddddddddddd ccccccccccccc vvv 2,python脚本 [root@localhost python]# vim 7.py f=open("/etc/motd") alllines = [lin