我目前正在执行以下操作,以使列表小写,然后删除点。
lowercase_list = [x.lower() for x in my_list]
lowercase_stripped_list = [x.replace('.', '') for x in lowercase_list]有没有办法在单行中做到这一点?
谢谢
发布于 2014-10-25 14:03:43
方法调用链(str.lower返回一个字符串,可以在返回值上调用另一个string方法str.replace ):
>>> my_list = ['Hello. World', 'Big.Big.World']
>>> [x.lower().replace('.', '') for x in my_list]
['hello world', 'bigbigworld']https://stackoverflow.com/questions/26563230
复制相似问题