2011年6月28日

摘要: #从一列表中,生成不重复的随机值#算法实现import randomtotal = 100li = [i for i in range(total)]res = []num = 20for i in range(num): t = random.randint(i,total-1) res.append(li[t]) li[t], li[i] = li[i], li[t]print res#python 已经实现这样的方法print random.sample(li, num) 阅读全文

posted @ 2011-06-28 14:55 蛇小狼 阅读(697) 评论(0) 推荐(0)

摘要: #单个字符替换s = 'abcd'a = ["a", "b", "c"]b = ["c", "d", "e"]import strings.translate(string.maketrans(''.join(a),''.join(b)))print s#字符串,改善版s = "hello, i'm mouren, hehe~~,hehe~~mourenmouren"a = ["mouren 阅读全文

posted @ 2011-06-28 14:51 蛇小狼 阅读(283) 评论(0) 推荐(0)