value value strip(value re sub('[!#?]'''valueremove punctuation value value title(result append(valuereturn result the result looks like thisin [ ]clean_strings(statesout[ ]['alabama''georgia''georgia''georgia''florida''south carolina''west virginia'an alternate approach that you may find useful is to make list of the operations you want to apply to particular set of stringsdef remove_punctuation(value)return re sub('[!#?]'''valueclean_ops [str stripremove_punctuationstr titledef clean_strings(stringsops)result [for value in stringsfor function in opsvalue function(valueresult append(valuereturn result then we have in [ ]clean_strings(statesclean_opsout[ ]['alabama''georgia''georgia''georgia''florida''south carolina''west virginia' more functional pattern like this enables you to easily modify how the strings are transformed at very high level the clean_strings function is also now more reusableyou can naturally use functions as arguments to other functions like the built-in map functionwhich applies function to collection of some kindin [ ]map(remove_punctuationstatesout[ ][alabama ''georgia'functions www it-ebooks info