Skip to content

Instantly share code, notes, and snippets.

# coding=gbk
import re
import urllib
#如何把name的编码转换成中文?
if __name__=='__main__':
f = open("touxiang.txt")
text = f.read()
l = text.split('},{')
re.findall(r'"name":"(.*)","head":"(.*)","groups":',text)
k = 1
#http://stackoverflow.com/questions/5037187/formatted-input-in-python/5040181#5040181 题解
f=open("x.txt")
d={}
flag=False
for l in f.readlines():
if not flag:
num=(len(l)-1)/2
flag=True
continue
for i in range(num):
@shihongzhi
shihongzhi / 重命名文件
Created January 19, 2011 03:57
重命名文件
import glob,os
if __name__ == '__main__':
p=r'E:\test1\*.jpg'
li = glob.glob(p)
k = 0
for f in li:
i = f.rindex('\\')
j = f.rindex('.')
newf = f.replace(f[i+1:j],'%04d'%(k))
@shihongzhi
shihongzhi / 1的数目
Created January 18, 2011 11:38
求0-13里的1的个数
reduce(lambda x,y:x+y,map(lambda x:str(x).count('1'), [t for t in range(13+1)]))
@shihongzhi
shihongzhi / assert_identitycard.py
Created January 2, 2011 04:58
身份证最后一位认证
#输出最后一位校验码
print (12-reduce(lambda x,y:x+y,map(lambda x:int(x[0])*x[1],zip('330225198708292872'[0:17],[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1])))%11)%11
#include <stdio.h>
#include <stdlib.h>
//strtok的实现和strtok_r一样,只是用一个static char*来维护saveptr
char *strtok_r(char *str,const char *delim,char **saveptr)
{
char *ret;
if(str==NULL)
str=*saveptr;
/*2010/11/18 shihongzhi
* 实现了printf,itoa,ftoa
* todo:%f的自定义小数点没有实现
*/
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
const double eps=1e-12;
#include <stdio.h>
#include <stdlib.h>
#define BITNUMBER 32
#define N 10000000
#define random(x) rand()%x
int a[N/BITNUMBER+1];
void set(int i)
#include <stdio.h>
#define BITNUMBER 32 //int占4个字节
#define N 32000
int a[N/BITNUMBER+1];
void set(int i)
{
a[i/BITNUMBER]|=1<<(i%BITNUMBER);
//http://zhedahht.blog.163.com/blog/static/25411174200732711051101/ 我是倒这过来做的
#include <stdio.h>
void print_sequence(int small,int big)
{
int i;
for(i=small;i<=big;i++)
printf("%d ",i);
printf("\n");
}