Skip to content

Instantly share code, notes, and snippets.

{"sig":"622d7ee0ecfb76f037511f3d7f64bf23ae46466551ad99f9124dce8b80ce2207d04b7dd8af9c5f50d24a9fa4bc6b20580af275bfb30359e93fc6f9f37ae272ed1","msghash":"ae1e2bb7c5704d063ad39d3fe0e0411d8ba55eb40ca6c18901d29c7cafdba9dd"}
@imbyron
imbyron / filter_3.x.py
Last active December 31, 2015 17:09
python3中filter的用法
text = "aAsmr3idd4bgs7Dlsf9eAF"
#只保留数字
list(filter(str.isdigit, text))
#只保留字母
list(filter(str.isalpha, text))
def f(x):return x%2 != 0 and x%3 != 0
list(filter(f,range(1,50)))
#结果:[1, 5, 7, 11, 13, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 49]
@imbyron
imbyron / m_n.py
Last active December 31, 2015 03:28
本程序会从1~n中随机取m个数,其中1<=m<=n
#!/usr/bin/python
#coding:utf-8
#author:byron
#blog:http://jiabin.tk
import random
def m_n():
print("本程序会从1~n中随机取m个数,1<=m<=n")
n = int(input("输入n的值:"))
m = int(input("输入m的值:"))
@imbyron
imbyron / qiubai.py
Last active December 22, 2015 14:18
糗百命令行版,最近学习正则表达式,抛弃了bs4,写了这么一个小爬虫,爬了糗百最近7天最热门的糗事儿。
#!/usr/bin/python
#coding:utf-8
#作者:Byron
#博客:http://jiabin.tk
import urllib2
import re
#定义程序主函数
def qiubai(page):
@imbyron
imbyron / hot_movies.py
Last active December 22, 2015 03:49
用Python的BeautifulSoup模块抓取豆瓣热映电影
#!usr/bin/python
#coding:utf-8
'''
@author:Byron
新浪围脖:http://weibo.com/ziyuetk
'''
import urllib2
from bs4 import BeautifulSoup
print "豆瓣正在热映:"
url = "http://movie.douban.com"
@imbyron
imbyron / city.py
Created July 24, 2013 11:41
全国城市代码列表 for weather.com.cn
# -*- coding: utf-8 -*-
city = {
'北京': '101010100',
'海淀': '101010200',
'朝阳': '101010300',
'顺义': '101010400',
'怀柔': '101010500',
'通州': '101010600',
'昌平': '101010700',
'延庆': '101010800',
@imbyron
imbyron / weather.py
Last active August 23, 2017 15:37
拙作:利用国家气象局的API查询天气的工具。
#!/usr/bin/python
#coding:utf-8
'''
@author:Byron
新浪微博:http://weibo.com/ziyuetk
'''
import urllib2, json
from city import city
yourcity = raw_input("你想查那个城市的天气?")
def foo(numbers=None):
if numbers is None:
numbers = []
numbers.append(9)
print numbers
def isEqual(num1,num2):
if num1 < num2:
print '%d is too small.' %num1
return False
if num1 > num2:
print '%d is too big.' %num1
return False
if num1 == num2:
print 'BINGO,you win!!!'
return True
@imbyron
imbyron / bingo.py
Last active December 19, 2015 10:09
from random import randint
num = randint(1,1000)
print 'Guess what i think?'
bingo = False
while bingo == False:
answer = input()
if answer < num:
print '%d is too small.' % answer
if answer > num: