Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3624843
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2019-03-07 11:05:22

[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 /]#


阅读(2636) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~