joke python
w
# -*- coding: utf-8 -*-
import pycurl
import re
import cStringIO
from pypinyin import lazy_pinyin import sys, locale buf = cStringIO.StringIO() GRAB_URL = 'http://www.gov.cn/test/2011-08/22/content_1930111.htm' c = pycurl.Curl()
c.setopt(c.HTTPHEADER, ['Accept-Charset: UTF-8'])
c.setopt(c.URL, GRAB_URL)
c.setopt(c.WRITEFUNCTION, buf.write)
c.perform() grab_data = buf.getvalue().decode('utf-8')
tmp_list = re.findall(r"\d{3}[^0]0{2}.*<", grab_data)
# 词尾一样
shi_dic = {}
# 词头一样
shi_dic_head = {}
for i in tmp_list:
tmp = i.split(' ')
city = tmp[1].split('<')
try:
shi_exist = city[0].index(u'市')
if shi_exist > 1:
# 深圳市
shi_tail = city[0].split(u'市')
# 深圳
shi = shi_tail[0]
shi_pinyin = lazy_pinyin(shi)
tail_pinyin = shi_pinyin[-1]
head_pinyin = shi_pinyin[0]
if shi_dic.has_key(tail_pinyin):
shi_dic[tail_pinyin].append(shi)
else:
shi_dic[tail_pinyin] = [shi] if shi_dic_head.has_key(head_pinyin):
shi_dic_head[head_pinyin].append(shi)
else:
shi_dic_head[head_pinyin] = [shi]
else:
continue
except Exception, e:
# print Exception, ":", e
continue def letsgo():
info = raw_input(u'请输入,如“深圳”:'.encode('utf-8')).decode(sys.stdin.encoding or locale.getpreferredencoding(True)) info_pinyin = lazy_pinyin(info)
info_shi_pinyin = info_pinyin[-1]
flag = 1
# if shi_dic.has_key(info_shi_pinyin):
# flag = 0
# for i in shi_dic[info_shi_pinyin]:
# print i
if shi_dic_head.has_key(info_shi_pinyin):
flag = 0
for i in shi_dic_head[info_shi_pinyin]:
print i
if flag == 1:
print "输入字符串非法"
die = raw_input(u'如继续,请输入go,如结束请输入其他')
if die == 'go':
letsgo()
else:
print '程序已经退出' letsgo()

joke python的更多相关文章
- Python写各大聊天系统的屏蔽脏话功能原理
Python写各大聊天系统的屏蔽脏话功能原理 突然想到一个视频里面弹幕被和谐的一满屏的*号觉得很有趣,然后就想用python来试试写写看,结果还真玩出了点效果,思路是首先你得有一个脏话存放的仓库好到时 ...
- python和数据科学(Anaconda)
Python拥有着极其丰富且稳定的数据科学工具环境.遗憾的是,对不了解的人来说这个环境犹如丛林一般(cue snake joke).在这篇文章中,我会一步一步指导你怎么进入这个PyData丛林. 你可 ...
- 笨办法学Python (exercise1-15)
#exercise1print "Hello world!"print "Hello Again"print "I like typing this. ...
- 《笨办法学Python》
习题一 第一个程序 print "Hello World!" print "Hello Evilxr" print "I like typing th ...
- Learn python the hard way. python test program 2016.04.27
# this will not be printed in python ! print "I could have code like this." # and the comm ...
- python分布式抓取网页
呵呵,前两节好像和python没多大关系..这节完全是贴代码, 这是我第一次写python,很多地方比较乱,主要就看看逻辑流程吧. 对于编码格式确实搞得我头大..取下来页面不知道是什么编码,所以先找c ...
- Python NLP入门教程
本文简要介绍Python自然语言处理(NLP),使用Python的NLTK库.NLTK是Python的自然语言处理工具包,在NLP领域中,最常使用的一个Python库. 什么是NLP? 简单来说,自然 ...
- Python NLTK 自然语言处理入门与例程(转)
转 https://blog.csdn.net/hzp666/article/details/79373720 Python NLTK 自然语言处理入门与例程 在这篇文章中,我们将基于 Pyt ...
- python 的类装饰器
我们都知道python的函数有装饰器,那么类也有装饰器吗?有的,为什么没有呢,来看下代码吧 def out(args): def inner(cls): cls._args = args return ...
随机推荐
- Mac019--Ubuntu上安装Rancher
首先安装:VisualBox虚拟机. 下载:ubuntu镜像 (ubuntu基于linux的免费开源桌面PC操作系统) ======================================== ...
- new Date() 对象及方法:
在别人的代码中见了两回 new Date().toLocaleString(),查了才知道,toLocaleString()是 根据本地时间格式,把 Date 对象转换为字符串.于是好奇new Dat ...
- mysql 函数 时间函数,数学函数,字符串函数,条件判断函数
=========================================== mysql 相关函数 ============================================= ...
- [Python3] 007 列表的遍历,你是 for 联盟还是 while 部落
目录 少废话,直接上例子 for 联盟 for 与 list 的简单合作 for 的老搭档 range() for 与嵌套列表(双层列表) for 从 if 那儿认识的 else 循环"三杰 ...
- .net core 自定义中间件
public class MyMiddleware { //private IConfiguration _configuration; //第一步: private RequestDelegate ...
- 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...
- 面向切面编程 AOP 和装饰器??
1.AOP概念:面向切面编程,指扩展功能不修改源代码,将功能代码从业务逻辑代码中分离出来. 主要功能:日志记录,性能统计,安全控制,事务处理,异常处理等等. 主要意图:将日志记录,性能统计,安全控制, ...
- spark复习笔记(5):API分析
0.spark是基于hadoop的mr模型,扩展了MR,高效实用MR模型,内存型集群计算,提高了app处理速度. 1.特点:(1)在内存中存储中间结果 (2)支持多种语言:java scala pyt ...
- 从后台看python--为什么说python是慢的
python越来越作为一种科学技术研究的语言越来越流行,可是我们经常听到一个问题,python是慢的.那么我们从后台分析一下,为什么python是慢的. python是一种动态类型,解释型语言,它的值 ...
- 你真的了解iOS的深浅拷贝吗?
最近在简书看到了一篇关于iOS深浅拷贝的博客,下面做一下学习总结: 非集合类对象的copy和mutableCopy 非集合类对象指NSString.NSNumber.NSMutableString等对 ...