文字列を個別の単語のリストに変換しようとしています-文字だけです。ただし、私が知る限り、ユニコードが問題を引き起こしています。
essay_text = ['This,', 'this,', 'this', 'and', 'that.']
def create_keywords(self):
low_text = self.essay_text.lower()
word_list = low_text.split()
abcs = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z']
for n in word_list:
for m in n:
for l in abcs:
if m!=l:
n.remove(m)
self.keywords.setdefault(n, 0)
self.keywords[n] = word_list.count(n)
for m in bad_words:
if n==m:
del self.keywords[n]
print self.keywords
次のエラーが表示されます。
AttributeError: 'unicode' object has no attribute 'remove'
どうすればこれを解決できますか?
更新: 文字列がユニコードである理由がわかりません。関連する場合、このモデルが存在するクラスは次のとおりです。
class Essay(models.Model):
title = models.CharField(max_length=100)
author = models.CharField(max_length=100)
email = models.EmailField(max_length=100)
essay_text = models.TextField()
sources = models.TextField()
def __unicode__(self):
return self.title
文字列がユニコードになっているのはなぜですか?