1、写函数,检查获取传入列表或者元祖的对象的所有奇数位索引的元素,并将作为新的列表返回给调用者

 #解1:
def lis(x):
lis_1 = []
for i in range(len(x)):
#循环下标
if i % 2 == 1:
lis_1.append(x[i])
return lis_1
test = lis([5,32,54,66,4])
print(test) #解2:利用切片
def lis(x):
new_lis = x[1::2]#下标从1开始,【::】代表所有,2代表步长
return new_lis
print(lis([21,423,65,76,3,2]))

2、写函数,判断用户传入的对象、(字符串、列表、元祖)长度是否大于5.

 def test(x):
if len(x) > 5:
return True
print(test([1,2,3]))

3、写函数,检查传入列表的长度,如果大于2,那么仅保留前2个长度的内容,并将新内容返回给调用者

def test(x):
if len(x) > 2 :
new_1 = x[0:2]
return new_1
print(test([2,3,5]))

4、写函数、计算传入字符串中的【数字】、【字母】、【空格】及【其他】的个数

 def num(x):
num_1 = 0
str_1 = 0
spac = 0
other = 0
for i in x:
if i.isdecimal():
num_1 += 1
elif i.isspace() :
spac += 1
elif i.isalnum() :
str_1 += 1
else:
other += 1
return {'数字':num_1,'字母':str_1,'空格':spac,'其他':other}
test = num('fjakla3224/ .2 &^@')
print(test)

最新文章

  1. Polly
  2. cheap gucci bags for women finish fashion jewellery has to move
  3. 基于Maven site的穷人的本地知识管理系统
  4. codeforces 83 D. Numbers
  5. Oracle行转列操作
  6. OD使用教程3
  7. 9.SpringMVC和json结合传递数据 && 10.SpringMVC获取controller中json的数据
  8. TCP/IP TIME_WAIT状态原理
  9. (转)Hessian(C#)介绍及使用说明
  10. 迅雷API:实现文件下载
  11. 如何通过fpmmm和zabbix来监控客户机上MariaDB数据库运行情况
  12. 水题 K
  13. linux Bash 常用
  14. python----函数与函数式编程
  15. 廖雪峰Java4反射与泛型-1反射-2访问字段Field和3调用方法Method
  16. socketserver模块实现并发和连接合法性验证
  17. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) F. Souvenirs 线段树套set
  18. 关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
  19. 每天一个linux命令(3):pwd
  20. (1)Oracle基础--用户与登录

热门文章

  1. FS获取KERNEL32基址的三种方法
  2. [NOIP模拟测试7]visit 题解(组合数学+CRT+Lucas定理)
  3. 浅谈C/C++中的static和extern关键字
  4. kmalloc vs vmalloc
  5. CSP2019总结
  6. 前端通过url页面传值
  7. ASP.NET中ajax验证用户名和邮箱是否重复
  8. laydate box-sizingCSS就会变形
  9. redis 部署方式及常见特性
  10. 基于角色访问控制的OA系统的设计与实现