0
freq_items = dict(filter(lambda k,v : float(v)/float(self.total_items) >= self.support, items_list.items()))

This line is giving me error, "lambda 1 missing positional argument: v". Anyone can help me out to figure this error.

1 Answer 1

1

In Python 2, it is possible to fix your program with argument tuple unpacking:

freq_items = dict(filter(lambda (k,v) : float(v)/float(self.total_items) >= self.support, items_list.items()))

This was removed in Python 3. But the following remains:

freq_items = dict(filter(lambda item: float(item[1])/float(self.total_items) >= self.support, items_list.items()))

However, you really should use a dictionary comprehension:

freq_items = {k:v for k,v in items_list.items() if float(v)/float(self.total_items) >= self.support}

Or if you prefer the dict constructor for 2.5 compatibility.

freq_items = dict(k,v for k,v in items_list.items() if float(v)/float(self.total_items) >= self.support)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.