如何通过非循环函数进行 python 做列表、字典等值的

1、用map进行运算
s = [“hEllO”,“iNteRneT”,“pEopLe”]
a = (map(lambda x: x.lower(), s))
b = list(a)
2、通过函数中添加分组数据及map函数直接做格式转换与计算
df[‘分组占比’] = (100*df[‘销售额’]/df[‘销售额’].sum(level = ‘月份’)).round(2).map(‘{}%’.format)
3、字典格式的赋值
citymr={‘芜湖’:‘WUHU’, ‘马鞍山’:‘MAANSHAN’, ‘淮南’:‘HUAINAN’, ‘宣城’:‘XUANCHENG’, ‘宿州’:‘SUZHOU’, ‘蚌埠’:‘BENGBU’, ‘阜阳’:‘FUYANG’,‘安庆’:‘ANQING’,‘池州’:‘CHIZHOU’, ‘淮北’:‘HUAIBEI’, ‘合肥’:‘HEFEI’, ‘亳州’:‘BOZHOU’,‘黄山’:‘HUANGSHAN’,‘铜陵’:‘TONGLING’,‘滁州’:‘CHUZHOU’, ‘六安’:‘LIUAN’}
citylist=[‘WUHU’, ‘MAANSHAN’, ‘HUAINAN’]

citylist=list(map(low(),citylist))

map(lambda x:x.lower() , citymr.values())

citymr=dict((k, v.lower()) for k, v in citymr.items())

你可能感兴趣的