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

yipeiwu_com7年前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: os.listdir(path) //path为目录 功能相当于在path目录下执行dir命令,返回为list类型 print os.listdir('..') 2: os.pat...

ubuntu安装sublime3并配置python3环境的方法

最近有一些烦,虚拟机跑代码,跑着跑着存储不够,我就去扩大磁盘,结果虚拟机崩了,试了一上午的修复办法,仍然无法修复,于是只能重装虚拟机,配置各种环境,这里总结一下Ubuntu中配置subl...

python+matplotlib实现礼盒柱状图实例代码

python+matplotlib实现礼盒柱状图实例代码

演示结果: 完整代码: import matplotlib.pyplot as plt import numpy as np from matplotlib.image impor...

python 实现视频流下载保存MP4的方法

如下所示: # -*- coding:utf-8 -*- import sys import os from glob import glob import requests...

在python里从协程返回一个值的示例

下面的例子演法了怎么样从协程里返回一个值: import asyncio async def coroutine(): print('in coroutine') ret...