[root@localhost /]#
[root@localhost /]# cat zlg.py
#!/bin/python
from random import randint
import time
mylist=[1,2,3,4]
mylist.reverse()
for x in mylist:
print x
mytuple=(1,2,3,4)
for y in range(len(mytuple)-1,-1,-1):
print mytuple[y]
mystr='hello you are a bitch'
print mystr.replace('bitch','butterfly')
import re
print re.sub('bitch','dog',mystr)
yourstr=' H '
def myrightstrip(str,splitstr):
index=str.rfind(splitstr)
while index != -1 and index == len(str)-1:
str=str[:index]
index=str.rfind(splitstr)
return str
def myleftstrip(str,splitstr):
index=str.find(splitstr)
while index == 0:
str=str[index+1:]
print str
time.sleep(4)
index=str.find(splitstr)
print index
return str
#print myleftstrip(yourstr,'')
print myrightstrip(yourstr,'')
def adder(num):
def adder2(num2):
return num+num2
return adder2
p1=adder(5)
p2=adder(4)
print p1(10)
print p2(10)
mylist=[{'name':'zlg','age':'12'},{'name':'zzzz','age':'13'},{'name':'hhhh','age':'14'}]
mylist.sort(key=lambda x:x.get('age'),reverse=False)
print mylist
list0=[1,2,3,4,5,6,7]
list9=[6,7,8,9,0]
def myunion(*argv):
print argv
s=set()
for i in argv:
print i
s=s.union(i)
print list(s)
myunion(list0,list9)
class Stack():
def __init__(self):
self.stack=[]
def push(self,x):
self.stack.append(x)
def pop(self):
self.stack.pop()
stack=Stack()
stack.push(1)
stack.push(2)
stack.push(3)
print stack.stack
stack.pop()
print stack.stack
abc=[randint(1,100) for _ in range(1,20)]
print abc
o=[1,2,3,4,5]
p=list(map(lambda x:x*x,o))
q=[x for x in p if x>10]
print q
[root@localhost /]# cat zhu.py
#!/bin/python
import re
a=[1,2,3,4]
a.reverse()
print a
b=(1,2,3,4)
for x in range(len(b)-1,-1,-1):
print b[x]
c='hello my girl'
print c.replace('girl','boy')
print re.sub('girl','boy',c)
d=[{'name':'zhu','age':18},{'name':'zlg','age':19},{'name':'zzz','age':17},{'name':'ggg','age':20}]
d.sort(key=lambda x:x.get('age'),reverse=False)
print d
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# cat zhu.py
#!/bin/python
a=[1,2,3]
c=' '.join(str(x) for x in a)
print c
e='abc'
f='def'
g=['d','e','f']
print e.join(f)
print e.join(g)
y=[[1,2],[3,4],[5,6]]
o=[]
p=[2,3]
q=[2,3]
map(o.extend,y)
p.extend(q)
print o
print p
[root@localhost /]#
阅读(2669) | 评论(0) | 转发(0) |