我如何在单个列表理解中编写下面的python代码,其中还涉及函数调用?

states = { 1:['Alabama@ ', 'Georgia!', 'Geor%gia%%', 'georgia', 'FlOrIda', 'southcarolina##', 'West virginia?']}

def remove_punctuations(value):
    return re.sub('[#!?@%]','',value) # remove these punctuations 

for_strings = [str.title, remove_punctuations, str.strip] # perform these  actions on strings 

def clean_strigs(strings,options):
    result = []
    for val in strings:
        #print(val)
        for function in options:
            val = function(val)
        result.append(val)
    return result

filter_dictonary(states[1],for_strings)

output = ['Alabama',
 'Georgia',
 'GeorGia',
 'Georgia',
 'Florida',
 'Southcarolina',
 'West Virginia']

我正在尝试使用具有理解力的方法编写clean_string函数,并且还尝试在其中调用for_list,但是我无法这样做,因此我尝试了以下代码

def filter_column(strings,for_strings):
    result =  [val for value in strings for function  in for_strings for val in function(val) ]
    return result

可以帮我写这个吗?

评论