• Common sequence manipulation functions


     1 # 常用序列操作函数
     2 # 1.all()
     3 list_1 = [1, 1.5, '1']
     4 print(all(list_1))
     5 list_2 = [0, 1, '1']
     6 print(all(list_2))
     7 list_3 = ['0', 1]
     8 print(all(list_3))
     9 '''
    10 True
    11 False
    12 True
    13 '''
    14 
    15 # 2.range(start,stop[,step)
    16 # 返回从start开始到stop(不包括stop)结束的可迭代对象,step为步数,start默认为0,step默认为1
    17 list_4 = list(range(5))
    18 list_5 = list(range(1, 6))
    19 list_6 = list(range(0, 9, 2))
    20 print(list_4)
    21 print(list_5)
    22 print(list_6)
    23 '''
    24 [0, 1, 2, 3, 4]
    25 [1, 2, 3, 4, 5]
    26 [0, 2, 4, 6, 8]
    27 '''
    28 
    29 # sorted()
    30 # 排序(升序)
    31 list_7 = [3, 2, 4, 6, 5, 7, 8]
    32 list_8 = sorted(list_7)
    33 print(list_8)
    34 # OUT:[2, 3, 4, 5, 6, 7, 8]
    35 
    36 # reversed()
    37 # 反转序列,返回可迭代对象
    38 r = reversed(list_8)
    39 print(r)
    40 list_9 = list(r)
    41 print(list_9)
    42 '''
    43 <list_reverseiterator object at 0x0000025FCCE7BD88>
    44 [8, 7, 6, 5, 4, 3, 2]
    45 '''
    46 
    47 # zip()
    48 # 将多个迭代对象相同位置的元素聚合成元组,返回一个以元组为元素的可迭代对象
    49 list_10 = ['a', 'b', 'c']
    50 list_11 = [1, 2, 3]
    51 z = zip(list_10, list_11)
    52 print(list(z))
  • 相关阅读:
    MySql锁机制
    Mysql存储引擎
    Linux 系统中安装mysql
    常见的系统架构
    Linux环境下搭建go开发环境
    Ajax概述
    正向代理和反向代理
    Mysql 存储过程以及在.net中的应用示例
    Mysql 事务
    Windows服务器实现自动化部署-Jenkins
  • 原文地址:https://www.cnblogs.com/Aoke/p/13598486.html
Copyright © 2020-2023  润新知