python map、join函数
map() 会根据提供的函数对指定序列做映射。
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。
map(function, iterable, ...)
其中
- function -- 函数,有两个参数
- iterable -- 一个或多个序列
- >>>def square(x) : # 计算平方数... return x ** 2...
- >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方
- [1, 4, 9, 16, 25]
- >>> map(lambda x: x ** 2, [1, 2, 3, 4, 5]) # 使用 lambda 匿名函数
- [1, 4, 9, 16, 25]
- # 提供了两个列表,对相同位置的列表数据进行相加
- >>> map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])
- [3, 7, 11, 15, 19]
join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
str.join(sequence)
- str = "-";
- seq = ("a", "b", "c"); # 字符串序列
- print str.join( seq );
split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串
str.split(str="", num=string.count(str))
- str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
- num -- 分割次数。
- str = "this is string example....wow!!!"
- print (str.split( ))
- print (str.split('i',1))
- print (str.split('w'))
- ['this', 'is', 'string', 'example....wow!!!']
- ['th', 's is string example....wow!!!']
- ['this is string example....', 'o', '!!!']
data_4temp1['amount2'] = data_4temp1['amount'].map(lambda x: int(''.join(x[1:].split(','))))
原文地址:https://blog.csdn.net/abcdrachel/article/details/80520484
python map、join函数的更多相关文章
- python中join()函数的使用方法
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...
- Python中join()函数方法
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...
- Python中join函数和os.path.join用法
Python中有join和os.path.join()两个函数,具体作用如下: join:连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 os.path.jo ...
- python的join()函数
def join(self, iterable): # real signature unknown; restored from __doc__ """ S.join( ...
- python中join()函数、list()函数补充的用法
---恢复内容开始--- Python join() 方法用于将序列中的元素(必须是str) 以指定的字符 连接生成一个新的字符串. list=[','a','b','c'] print(''.joi ...
- Python的join()函数和split()函数
join()方法 ------------------------------------------------------------------------------------------- ...
- python中join函数的用法
这个函数可以对字符串按照某种方式进行拼接,比如你要在三个字母中间都添加一个特定字符,就可以用这个函数实现 result = '*'.join(['A','B','C']) print(result) ...
- python语法join函数
Python语法中join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串. vid = )
- Python:.join()函数
转于:https://blog.csdn.net/chixujohnny/article/details/53301995 博主:chixujohnny 介绍:.join是一个字符串操作函数,将元素相 ...
- python中join()函数讲解
本文简述的是string.join(words[, sep]),它的功能是把字符串或者列表,元组等的元素给连接起来,返回一个字符串,和split()函数与正好相反,看下面的代码理解. a=[" ...
随机推荐
- Latex中遇到 No room for a new \count 问题的解决
在tex文件中加入etex宏包. \usepackage{etex} 最好加载第一个宏包位置 PDF合并 \documentclass[a4paper]{article}\usepackage{pdf ...
- many connection errors,更改max_connection_errors的值
https://www.cnblogs.com/tonyccc/p/11496101.html https://blog.csdn.net/li_li_lin/article/details/7276 ...
- (转)java 虚拟机内存划分
深入理解java虚拟机(一):java内存区域(内存结构划分)深入理解java虚拟机(二):java内存溢出实战 深入理解java虚拟机(三):String.intern()-字符串常量池深入理解j ...
- 【做题笔记】洛谷P1506 拯救oibh总部
跑一遍染色法,最后判断哪些位置没被染色即可 一些技巧: 为了判断方便,把字符转换成 int 型的数字. 注意边界问题 详细解释见代码 #include <iostream> #includ ...
- CTF——代码审计之变量覆盖漏洞writeup【1】
题目: 所需基础知识: 分析: 思路:由于目的是要拿$flag的值,所以可以得出最终会输出两个变量,而$flag的值在红框那行,被我们自己post的值给覆盖,所以flag值肯定不会在这出来,那么只剩下 ...
- opensuse安装pycharm
最近在学习python,所以查询了很多资料,大多都推荐pycharm进行pychon项目开发.于是查阅一些资料,整理出这个安装步骤.(仅供参考!!!仅供参考!!!仅供参考!!!) 仅供参考!!!仅供参 ...
- 组合数的计算以及组合数对p取余后结果的计算
前奏:统计 n! 中的所有质因子中pi的个数 普通方法:复杂度O(nlogn), 当n为10的18次方无法承受 // 复杂度O(nlogn), n为10的18次方无法承受 int cal(int n, ...
- 1、Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- linux命令 mv
后缀--backup=<备份模式>:若需覆盖文件,则覆盖前先行备份: -b:当文件存在时,覆盖前,为其创建一个备份: -f:若目标文件或目录与现有的文件或目录重复,则直接覆盖现有的文件或目 ...
- ubuntu 离线装包
1,为什么要离线装包 防止有些包官方升级以后导致的不兼容,比如php5和php7,目前已经无法apt-get install php5了, 2,装包以前你得有安装包文件,deb或者是run deb包在 ...