__director

2020年4月25日

shell 随机产生字符串或数字

摘要: 产生字符串:法一:echo $RANDOM |md5sum |cut -c 1-6 #这里是产生6位,可以有1-32位 法二: cat /proc/sys/kernel/random/uuid |cut -c 1-8 ed9e032c #这里是产生8位,可以有1-36位 产生数字 法一:date + 阅读全文

posted @ 2020-04-25 15:51 __director 阅读(377) 评论(0) 推荐(0) 编辑

判断三点能否构成三角形

摘要: listA = [(2,3),(3,5),(5,7)] listB = [(1,2),(2,4),(4,8)] def tri(arg): x0,y0 = arg[0] x1,y1 = arg[1] x2,y2 = arg[2] if (y0-y1)*(x0-x2) == (y0-y2)*(x0-x 阅读全文

posted @ 2020-04-25 15:26 __director 阅读(1034) 评论(0) 推荐(0) 编辑

通过函数实现十进制转二进制

摘要: def func(n, first=True): if n == 0: if first: return '0b0' else: return '0b' return str(func(n//2, False))+str(n%2) print(func(0)) print(func(3)) prin 阅读全文

posted @ 2020-04-25 14:37 __director 阅读(470) 评论(0) 推荐(0) 编辑

统计重复字符串并排序

摘要: string = 'aovbzoasvaobvdoaobgvo;sogvosov;svgoas;shvbpe;;svoovohoaosobvboeaso' string_set = list(set(string)) print(string_set) conuts = list(map(strin 阅读全文

posted @ 2020-04-25 14:25 __director 阅读(137) 评论(0) 推荐(0) 编辑

time 模块

摘要: time.time() #获取当前时间戳 1587743489.9542704 time.localtime() #获取本地时间,年月日时分秒周,一年中第几天 time.struct_time(tm_year=2020, tm_mon=4, tm_mday=24, tm_hour=23, tm_mi 阅读全文

posted @ 2020-04-25 00:12 __director 阅读(108) 评论(0) 推荐(0) 编辑

2020年4月24日

awk 按多个字符进行切割

摘要: [root@xiaoyuan ~]# ip a s eth0 | grep inet inet 172.31.142.158/20 brd 172.31.143.255 scope global dynamic eth0 inet 192.168.170.133/24 brd 192.168.170 阅读全文

posted @ 2020-04-24 23:54 __director 阅读(958) 评论(0) 推荐(0) 编辑

shell 算数运算

摘要: expr: [root@xiaoyuan ~]# expr 2+4 # 需要空格 2+4[root@xiaoyuan ~]# expr 2 + 46[root@xiaoyuan ~]# expr 2 * 4 # *需要转义,不然报错expr: syntax error[root@xiaoyuan ~ 阅读全文

posted @ 2020-04-24 23:43 __director 阅读(75) 评论(0) 推荐(0) 编辑

sell 实现100内偶数和

摘要: #法一 seq -s+ 0 2 100 | bc #法二 awk 'BEGIN{for(i=0;i<=100;i++){if(!(i%2))sum+=i};print sum}' #法三 #!/bin/bash #date 2020/4/24 for i in `seq 100`;do if [ ` 阅读全文

posted @ 2020-04-24 23:28 __director 阅读(113) 评论(0) 推荐(0) 编辑

sort 实现逐行排序

摘要: 加r为逆序 阅读全文

posted @ 2020-04-24 23:13 __director 阅读(111) 评论(0) 推荐(0) 编辑

反转字符串

摘要: #!/bin/bash read -p '请输入:' string size=${#string} for ((i=$size-1;i>=0;i--));do printf "${string:$i:1}" done echo '' 阅读全文

posted @ 2020-04-24 23:02 __director 阅读(81) 评论(0) 推荐(0) 编辑

导航