我是Python新手。当我运行以下代码时出现此错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-cdb5a334e110> in <module>
16
17 duplicates_removed = clean_strings
---> 18 duplicates_removed = list(dict.fromkeys(duplicates_removed))
19 print(duplicates_removed)
TypeError: 'function' object is not iterable
有人可以指出我正确的方向吗?
代码
import re
def remove_punctuation(value):
return re.sub('[!#?]', '', value)
clean_ops = [str.strip, remove_punctuation, str.title]
def clean_strings(strings, ops):
result = []
for value in strings:
for function in ops:
value = function(value)
result.append(value)
return result
clean_strings(states_1, clean_ops)
duplicates_removed = clean_strings
duplicates_removed = list(dict.fromkeys(duplicates_removed))
print(duplicates_removed)
慕田峪4524236
有只小跳蛙
holdtom
相关分类