map() 会根据提供的函数对指定序列做映射。

第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。

map(function, iterable, ...)

其中

  • function -- 函数,有两个参数
  • iterable -- 一个或多个序列
  1.  
    >>>def square(x) : # 计算平方数... return x ** 2...
  2.  
    >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方
  3.  
    [1, 4, 9, 16, 25]
  4.  
    >>> map(lambda x: x ** 2, [1, 2, 3, 4, 5]) # 使用 lambda 匿名函数
  5.  
    [1, 4, 9, 16, 25]
  6.  
    # 提供了两个列表,对相同位置的列表数据进行相加
  7.  
    >>> map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])
  8.  
    [3, 7, 11, 15, 19]

join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。

str.join(sequence)
  1.  
    str = "-";
  2.  
    seq = ("a", "b", "c"); # 字符串序列
  3.  
    print str.join( seq );

split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串

str.split(str="", num=string.count(str))
  • str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
  • num -- 分割次数。
  1.  
    str = "this is string example....wow!!!"
  2.  
    print (str.split( ))
  3.  
    print (str.split('i',1))
  4.  
    print (str.split('w'))
  5.  
     
  6.  
    ['this', 'is', 'string', 'example....wow!!!']
  7.  
    ['th', 's is string example....wow!!!']
  8.  
    ['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函数的更多相关文章

  1. python中join()函数的使用方法

    函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下:    join():    连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...

  2. Python中join()函数方法

    函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下:    join():    连接字符串数组.将字符串.元组.列表中的元素以指定的字 ...

  3. Python中join函数和os.path.join用法

    Python中有join和os.path.join()两个函数,具体作用如下: join:连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串 os.path.jo ...

  4. python的join()函数

    def join(self, iterable): # real signature unknown; restored from __doc__ """ S.join( ...

  5. python中join()函数、list()函数补充的用法

    ---恢复内容开始--- Python join() 方法用于将序列中的元素(必须是str) 以指定的字符 连接生成一个新的字符串. list=[','a','b','c'] print(''.joi ...

  6. Python的join()函数和split()函数

    join()方法 ------------------------------------------------------------------------------------------- ...

  7. python中join函数的用法

    这个函数可以对字符串按照某种方式进行拼接,比如你要在三个字母中间都添加一个特定字符,就可以用这个函数实现 result = '*'.join(['A','B','C']) print(result) ...

  8. python语法join函数

    Python语法中join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串. vid = )

  9. Python:.join()函数

    转于:https://blog.csdn.net/chixujohnny/article/details/53301995 博主:chixujohnny 介绍:.join是一个字符串操作函数,将元素相 ...

  10. python中join()函数讲解

    本文简述的是string.join(words[, sep]),它的功能是把字符串或者列表,元组等的元素给连接起来,返回一个字符串,和split()函数与正好相反,看下面的代码理解. a=[" ...

随机推荐

  1. vue.js中使用离线检测

    Html5在window.navigator对象上添加了一个属性onLine 返回布尔值 true表示在线.同时新增了两个事件: window.addEventListener('online', f ...

  2. 机器学习作业(四)神经网络参数的拟合——Matlab实现

    题目下载[传送门] 题目简述:识别图片中的数字,训练该模型,求参数θ. 第1步:读取数据文件: %% Setup the parameters you will use for this exerci ...

  3. C语言运算符的优先级与结合性

    结合性:左结合是从左到右依次执行,右结合是从右到左依次执行. 优先级 运算符 名称或作用 运算类型 结合方向 特点 1 () [] -> . 小括号运算符 下标运算符 指向结构成员运算符 结构成 ...

  4. Appnium 环境搭建

    NodeJs 下载安装 npm install -g appium-doctor Java JDK jdk-8u241-windows-x64 添加环境变量:JAVA_HOME 在环境变量Path中添 ...

  5. Codeforces Round #601 (Div. 2) A Changing Volume

    好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include&l ...

  6. 《Mongo权威指南》学习手记

    1.ObjectId: 是“_id”的默认类型.mongo没有用自增主键原因:多个服务器同步自动增加主键值费时费力. mongo初衷是作分布式数据库,所以能在分片环境中生成唯一的标示符非常重要. Ob ...

  7. VS2017连接MySQL数据库

    vs默认无法直接连接mysql,需要我们自己配置环境. 1.下载mysql-installer-community-8.0.18.0.msi 下载地址:https://dev.mysql.com/do ...

  8. The number of set(位运算+状态dp)一道十分美妙的题目哦!!!!!!

    Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use the ...

  9. Ubuntu16.04配置

    一.将源更换为国内的源,这样下载和更新软件的速度会快很多.将/etc/apt/sources.list文件的内容更换为如下: #默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消 ...

  10. Makefile文件(DE1-soc软件实验”hello_word")

    DE1-soc软件实验”hello_word"中,hello_word此程序很好理解,那Makefile文件又如何理解呢? 所要完成的Makefile 文件描述了整个工程的编译.连接等规则. ...