While studying Python scraping, when I was processing values, I got ʻAttribute Error:'list' object has no attribute'replace'`, so I will leave a countermeasure in the memo
I was trying to write logic to delete a specific string in a list obtained by Python. But the error => ʻAttributeError:'list' object has no attribute'replace'`
>>> str_list = ['aaabbb','article']
>>> str_list_new = str_list.replace('a', '')
AttributeError: 'list' object has no attribute 'replace'
It seems that you should convert the array to a single character string, replace it with replace (), and then return it to the array.
>>> str_list = ['aaabbb','article']
>>> str_list_new = [item.replace('a', '') for item in str_list]
>>> str_list_new
['bbb', 'rticle']
reference https://spcx8.hatenablog.com/entry/2017/07/05/204423
Recommended Posts