Returning top items from list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • egg0579
    New Member
    • Mar 2007
    • 3

    #1

    Returning top items from list

    I have a situation where I have two list of strings(single words) created from reading in text. The first list is ordered by frequency of which the words appear in the text (minus stop words), and then the second list is unordered.

    What I need to do is compare the unordered list to the ordered one, and return the top 2 words that appear most frequently in the ordered list.

    Can't think how to do this at all. I am currently just returning all words that appear in both by using for loops and the cmp() method.

    Any suggestions would be great.....Thank s
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by egg0579
    I have a situation where I have two list of strings(single words) created from reading in text. The first list is ordered by frequency of which the words appear in the text (minus stop words), and then the second list is unordered.

    What I need to do is compare the unordered list to the ordered one, and return the top 2 words that appear most frequently in the ordered list.

    Can't think how to do this at all. I am currently just returning all words that appear in both by using for loops and the cmp() method.

    Any suggestions would be great.....Thank s
    This actually sound just like this problem.

    Comment

    • egg0579
      New Member
      • Mar 2007
      • 3

      #3
      Originally posted by bartonc
      This actually sound just like this problem.
      Maybe I'm confused but is it??

      I have a list like this (a lot longer), which already has the words sorted in their frequency order:

      sortedWords = ["hello", "test", "said", "once", "example"]

      and another list of say 10 or so words, that are also present in the sorted list.

      I want to iterate through my shorter list and return the top 2 words that appear first in the sortedWords list.

      Sorry if I've missed the point but been a few years since I've coded with python.

      Comment

      • egg0579
        New Member
        • Mar 2007
        • 3

        #4
        Originally posted by egg0579
        Maybe I'm confused but is it??

        I have a list like this (a lot longer), which already has the words sorted in their frequency order:

        sortedWords = ["hello", "test", "said", "once", "example"]

        and another list of say 10 or so words, that are also present in the sorted list.

        I want to iterate through my shorter list and return the top 2 words that appear first in the sortedWords list.

        Sorry if I've missed the point but been a few years since I've coded with python.
        Think I've sorted it now. Cheers

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by egg0579
          Think I've sorted it now. Cheers
          There's help here if you need it. Sorry that I was in such a rush today (lunch time PST).

          Comment

          Working...