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能有所帮助,如果有疑问大家可以留言交流。

相关文章

Python文件和流(实例讲解)

1.文件写入 #打开文件,路径不对会报错 f = open(r"C:\Users\jm\Desktop\pyfile.txt","w") f.write("Hello,world!\...

Python合并字符串的3种方法

目的   将一些小的字符串合并成一个大字符串,更多考虑的是性能 方法    常见的方法有以下几种: 1.使用+=操作符 复制代码 代码如下:   BigString=small...

python实现文本文件合并

python合并文本文件示例代码。 python实现两个文本合并 employee文件中记录了工号和姓名 cat employee.txt: 100 Jason Smith 20...

python绘制立方体的方法

python绘制立方体的方法

本文实例为大家分享了python绘制立方体的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # This is (almost) a direct...

Python中__repr__和__str__区别详解

看下面的例子就明白了 class Test(object): def __init__(self, value='hello, world!'): self.data =...