this question may seem stupid for those who are familier with Python. however, it puzzles me a lot. when i tried to extrect words whose frequency is above 200, following codes works, but how to implement this function with "class"is a problem.
i have tried following codes,but i did not work.
v1 = cs(v)
v11 = v1.caltext()
Code:
v= [('make', 207), ('one', 206), ('people', 196), ('go', 189), ('say', 180), ('get', 160), ('time', 150), ('take', 141), ('would', 137), ('like', 134), ('b', 130), ('know', 119), ('find', 118), ('woman', 117), ('work', 117), ('c', 116), ('d', 114), ('use', 114), ('two', 113), ('year', 108), ('book', 106), ('think', 106), ('come', 104), ('good', 100), ('man', 100), ('child', 98), ('new', 98), ('way', 95), ('day', 93)]
a = []
for q,w in v:
if w > 200:
a.append(q)
Code:
class cs(object):
def __init__(self,text):
self.a = text
self.w = []
def caltext(self):
for q,v in self.a:
if v > 200:
self.w.append(q)
return w
v11 = v1.caltext()
Comment