How to count line number of incorrect words in a set using a dictionary

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lightning18
    New Member
    • May 2010
    • 16

    #16
    still get the same error
    Code:
    import sys
    import string
    
    text = []
    infile = open(sys.argv[1], 'r').read()
    for punct in string.punctuation:
        infile = infile.replace(punct, "")
        text = infile.split("\n")
        
    dict = open(sys.argv[2], 'r').read()
    dictset = []
    dictset = dict.split()
        
    words = []
    words = list(set(text) - set(dictset))
    words = [text.lower() for text in words]
    words.sort()
    
    
    def findline(text, word):
        ans = []
        reps = text.count(word)
        n = 0
        for i in range(reps):
            ans.append(text[n:].index(word)+n)
            n = text[n:].index(word)+1
        return ans
    for w in words:
        print(w,findline(text, w)

    Comment

    • Glenton
      Recognized Expert Contributor
      • Nov 2008
      • 391

      #17
      I wasn't trying to solve your syntax error. You need to post more details or do your own debugging. There's normally a clue about where the syntax error is with whatever compiler your using.

      Although looking through your line 29 is wrong. print w,etc instead of print(w,etc

      Incidentally lines 4,7 and 14 are not needed.

      Comment

      • lightning18
        New Member
        • May 2010
        • 16

        #18
        Originally posted by Glenton
        I wasn't trying to solve your syntax error. You need to post more details or do your own debugging. There's normally a clue about where the syntax error is with whatever compiler your using.

        Although looking through your line 29 is wrong. print w,etc instead of print(w,etc

        Incidentally lines 4,7 and 14 are not needed.
        im using python
        and this is my first program i have ever made in my life
        so im not good with syntax
        the code i showed u is fully what i have
        the rror im getting is on line 29 all the time

        Comment

        • Glenton
          Recognized Expert Contributor
          • Nov 2008
          • 391

          #19
          Originally posted by lightning18
          im using python
          and this is my first program i have ever made in my life
          so im not good with syntax
          the code i showed u is fully what i have
          the rror im getting is on line 29 all the time
          As I said in my previous message replace line 29 with this:
          Code:
          print w,findline(text, w)
          Your current line 29 doesn't have matching brackets.

          Comment

          • lightning18
            New Member
            • May 2010
            • 16

            #20
            Originally posted by Glenton
            As I said in my previous message replace line 29 with this:
            Code:
            print w,findline(text, w)
            Your current line 29 doesn't have matching brackets.
            it still gives me a synatx error for
            Code:
             print w,findline(text, w)
            Code:
            import sys
            import string
            
            
            infile = open(sys.argv[1], 'r').read()
            for punct in string.punctuation:
                text = infile.split()
                
            dict = open(sys.argv[2], 'r').read()
            dictset = []
            dictset = dict.split()
                
            words = list(set(text) - set(dictset))
            words = [text.lower() for text in words]
            words.sort()
            
            
            def findline(text, word):
                ans = []
                reps = text.count(word)
                n = 0
                for i in range(reps):
                    ans.append(text[n:].index(word)+n)
                    n = text[n:].index(word)+1
                return ans
            for w in words:
                print w,findline(text, w)

            Comment

            • Glenton
              Recognized Expert Contributor
              • Nov 2008
              • 391

              #21
              I'm afraid I have no idea why. You're going to have to debug it. This is a normal part of coding. Try commenting out bits of the code and rerunning, until you narrow it down to where it is.

              Good luck!

              Comment

              Working...