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 ...
随机推荐
- pandas入门(1)
import pandas as pd import numpy as np # 自动创建索引 obj = pd.Series([4, 7, -5, 2]) print(obj, type(obj)) ...
- JDK 13 的 12 个新特性,真心涨姿势了
作者:木九天 my.oschina.net/mdxlcj/blog/3107021 1.switch优化更新 JDK11以及之前的版本: switch (day) { case MONDAY: cas ...
- C# http post请求帮助类
using System; using System.Collections.Specialized; using System.IO; using System.Net; using System. ...
- 跨域问题解决----NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost:11000' is therfore not allowed access'
NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost ...
- Vue/React如何优雅的一劳永逸的注册路由及组件
原文链接: 本人掘金文章 假如图片看不清晰可前往掘金原文预览 官方文档: 组建注册 路由注册 未优化版: 在Vue官方文档 中,我们通过 Vue.component('MyComponentNam ...
- linux相关认证和权限配置
[root@rsync-server-1 /]# echo 'rsync_backup:redhat' > /etc/rsync.password [root@rsync-server-1 /] ...
- ORI-621龙芯3A处理器CPCI刀片计算机
ORI-621龙芯3A处理器CPCI刀片计算机 一.产品简介 ORI -621是一款基于龙芯3A国产CPU处理器的特种CPCI刀片计算机.该产品成功地实现了服务器NUMA架构在国产特种计算机中的应用, ...
- Sass @warn
@warn 和 @debug 功能类似,用来帮助我们更好的调试 Sass.如: @mixin adjust-location($x, $y) { @if unitless($x) { @warn &q ...
- [CF] 8C Looking for Order
状压模板题 CF难度2000? 我得好好了解一下CF的难度机制了 反正CF的难度比洛谷真实就好了 Code #include<algorithm> #include<iostream ...
- django权限之二级菜单
遗漏知识点 1.构建表结构时,谁被关联谁就是主表,在层级删除的时候,删除子表的时候,主表不会被删除,反之删除主表的话,字表也会被删除, 使用related_name=None 反向查询,起名用的 ...