Python
2thing
这个作者很懒,什么都没留下…
展开
-
用pil模拟一下小时候的一个玩具
以前玩过个玩具,类似于齿轮,一个小齿轮在一个大齿轮里面转,把笔插入那个小齿轮的小孔,然后一圈一圈转,就有了一个神奇的图案。用python写了下,也不知对不对,图是出来了,分析了一下规律,应该就是一个公转自转问题。下面上代码: [code="python"] #! /usr/bin/env python #coding=utf-8 import Image,ImageDraw,sys,mat...2011-04-23 14:27:56 · 120 阅读 · 0 评论 -
Project Euler每帖一题(001)
[quote]题目:If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.[/...原创 2011-05-10 20:44:31 · 98 阅读 · 0 评论 -
Project Euler每帖一题(002)
题目: [quote] Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... ...原创 2011-05-10 21:37:27 · 100 阅读 · 0 评论 -
Project Euler每帖一题(006)
题目: [quote] The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 ...原创 2011-05-11 08:49:01 · 157 阅读 · 0 评论 -
Project Euler每帖一题(005)
题目: [quote]2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the nu...原创 2011-05-11 10:34:32 · 113 阅读 · 0 评论 -
一个字符串处理实例
这个示例实现的功能: 将文本中类似于‘21-12-2011’这样的日期类型找出来,替换为‘2011-12-21’ 上代码: [code="python"]import re pat = '\d{1,2}-\d{1,2}-\d{4}' p = re.compile(pat) f = open('c:/oreacle++emp.txt') t = f.readline() while ...2011-05-22 08:05:08 · 175 阅读 · 0 评论 -
python转码
首先用utf8编码形式写一个测试用的txt文件 [code="python"] >>> file = open('test.txt','r') >>> txt = file.read() >>> txt '\xe8\xbf\x99\xe6\x98\xaf\xe4\xb8\x80\xe4\xb8\xaa\xe6\xb5\x8b\xe8\xaf\x95\xe6\x96\x87\xe4\xbb...原创 2011-07-23 17:21:05 · 270 阅读 · 0 评论 -
Python多线程实例
[code="python"] from threading import Thread class Task(Thread): def __init__(self, count): super(Task, self).__init__() #Thread.__init__(self) self.count = count ...原创 2011-07-26 22:00:59 · 124 阅读 · 0 评论 -
python map/filter/reduce(转)
python有几个内置的函数很有意思:map/filter/reduce,都是对一个集合进行处理,filter很容易理解用于过滤,map用于映射,reduce用于归并,这几个词还是太抽象了,下面的代码精确的说明了这几个函数的用途: [quote]map[/quote] [code="python"]def map_imp(function, sequence) : if fu...原创 2011-07-28 21:59:28 · 108 阅读 · 0 评论