I know there is a good way to sort by the items frequency in python, but my question is how to keep only the items which have the frequency >1? Could anyone helps me? I prefer the format of result like this: [('banana', 3), ('apple', 2)]. Thank you in advance!

EDIT: This was repeatedly edited because I kept having things too hacky. This is a bit verbose but I would argue the most readable. Some unpacking wasn't entirely necessary, but that's what I ended up with.

Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.

I'm not sure actually. I thought he requested a dict my first time through but I may have just misread. Also reading the description of counter it sounds like the frequency ordering might be a fluke. The description states that it is every bit as unordered as a standard dict, so my last suggestion wouldn't have helped if this is indeed the case.

It uses hashing, which is unordered in the sense that it might seem like it is but you cannot rely on it. Here's a fun read about the generic data structure used internally in Python to implement dictionaries. Very good basic knowledge. It's second year material at my university, typically after 2-3 quarters of other programming but after an introduction to OOP.

Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.