Python实现将不规范的英文名字首字母大写

yipeiwu_com6年前Python基础

例如

输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart']。

方法一

def wgw(x): 
  return [x[0].upper(),x[1:].lower()] 
 
map(wgw,['adam','LISA','barT']) 

方法二

def wgw1(x): 
  return x.capitalize() 
 
map(wgw1,['adam','LISA','barT']) 

方法三

map(lambda x:x.capitalize(),['adam','LISA','barT']) 

总结

以上就是Python实现将不规范英文名字首字母大写,其他小写的规范名字的全部内容,希望本文的内容对大家学习或者使用python能有所帮助,如果有疑问大家可以留言交流。

相关文章

python3.7 openpyxl 删除指定一列或者一行的代码

python3.7 openpyxl 删除指定一列或者一行 # encoding:utf-8 import pandas as pd import openpyxl xl = pd....

python pygame实现五子棋小游戏

今天学习了如何使用pygame来制作小游戏,下面是五子棋的代码,我的理解都写在注释里了 import pygame # 导入pygame模块 print(pygame.ver) #...

使用python turtle画高达

使用python turtle画高达

我就废话不多说了,直接上代码吧! import turtle t=turtle.Turtle() turtle.Turtle().screen.delay(0) tleft=turt...

Python基于whois模块简单识别网站域名及所有者的方法

Python基于whois模块简单识别网站域名及所有者的方法

本文实例讲述了Python基于whois模块简单识别网站域名及所有者的方法。分享给大家供大家参考,具体如下: 对于一些网站,我们可能会关心其所有者是谁。为了找到网站的所有者,我们可以使用...

Python读取mat文件,并转为csv文件的实例

初学Python,遇到需要将mat文件转为csv文件,看了很多博客,最后找到了解决办法,代码如下: #方法1 from pandas import Series,DataFrame...