菜鸟养成第11集

filter函数

filter 函数用于过滤序列 ,它接收一个函数和一个序列,把函数作用在序列的每个元素上,然后根据返回值是True还是False决定保留还是丢弃该元素

python 复制代码
>>> mylist = list(range(10))
>>> list(filter(lambda x: x % 2 == 1, mylist))
[1, 3, 5, 7, 9]

zip函数

zip() 函数将可迭代的对象作为参数将对象中对应的元素打包成一个元组 ,然后返回由这些元组组成的列表

python 复制代码
>>> list1 = ['zhangfei', 'guanyu', 'liubei', 'zhaoyun']
>>> list2 = [0, 3, 2, 4]
>>> list(zip(list1, list2))
[('zhangfei', 0), ('guanyu', 3), ('liubei', 2), ('zhaoyun', 4)]

Counter函数

统计字符串中各个字符数个数

Counter(s)并且用字典的方式返回如下信息:

Counter({'f': 3, '9': 3, 'h': 2, '3': 2, 'w': 1, 'a': 1, 'u': 1, '2': 1, 'e': 1, 'r': 1, 'i': 1, '0': 1, '4': 1, 'j': 1, '-': 1})

shuffle函数

打乱一个列表

相关推荐
程序员的世界你不懂4 小时前
Appium+python自动化(八)- 认识Appium- 下章
python·appium·自动化
恸流失4 小时前
DJango项目
后端·python·django
Julyyyyyyyyyyy5 小时前
【软件测试】web自动化:Pycharm+Selenium+Firefox(一)
python·selenium·pycharm·自动化
蓝婷儿6 小时前
6个月Python学习计划 Day 15 - 函数式编程、高阶函数、生成器/迭代器
开发语言·python·学习
love530love6 小时前
【笔记】在 MSYS2(MINGW64)中正确安装 Rust
运维·开发语言·人工智能·windows·笔记·python·rust
水银嘻嘻7 小时前
05 APP 自动化- Appium 单点触控& 多点触控
python·appium·自动化
狐凄7 小时前
Python实例题:Python计算二元二次方程组
开发语言·python
烛阴8 小时前
Python枚举类Enum超详细入门与进阶全攻略
前端·python
Mikhail_G9 小时前
Python应用函数调用(二)
大数据·运维·开发语言·python·数据分析
weixin_472339469 小时前
使用Python提取PDF元数据的完整指南
java·python·pdf