作者: Peace & Love
来自:https://blog.youkuaiyun.com/u013205877/article/details/77542837
1.如何反向迭代一个序列
如果是一个list,最快的方法使用reverse
tempList = [1,2,3,4]
tempList.reverse()
for x in tempList:
print x
如果不是list,需要手动重排
templist = (1,2,3,4)
for i in range(len(templist)-1,-1,-1):
print templist[i]
2.如何查询和替换一个文本中的字符串
#最简单的方法使用replace()
tempstr = "hello you hello python are you ok"
print tempstr.replace("you","python")
#还可以使用正则,有个sub()
tempstr = "hello you hello python are you ok"
import re
rex = r'(hello|Use)'
print re.sub(rex,"Bye",tempstr)
3.使用python实现