Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:00:20+00:00 2026-05-13T19:00:20+00:00

Hi:) I am not able to figure out what the error in the program

  • 0

Hi:) I am not able to figure out what the error in the program is could you please help me out with it. Thank you..:)

The input file contains the following:

3.  भारत का इतिहास काफी समृद्ध एवं विस्तृत है।
57. जैसे आज के झारखंड प्रदेश से, उन दिनों, बहुत से लोग चाय बागानों में मजदूरी करने के उद्देश्य से असम आए।

( its basically sample sentences for which i need to get word positions in the output appended to each word in hindi)

for e.g the output for the first sentence would look like this:

3.  भारत(1) का(2) इतिहास(3) काफी(4) समृद्ध(5) एवं(6) विस्तृत(7) है(8) ।(9)

I should get a similar op for the following sentence(s)

The code looks like this:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# encoding: utf-8
separators = [u'।', ',', '.']
text = open("hinstest1.txt").read()
#This converts the encoded text to an internal unicode object, where
# all characters are properly recognized as an entity:
text = text.decode("UTF-8")
#this breaks the text on the white spaces, yielding a list of words:
words = text.split()

counter = 1

output = ""
#if the last char is a separator, and is joined to the word:
for word in words:
    if word[-1] in separators and len(word) > 1:
        #word up to the second to last char:
        output += word[:-1] + u'(%d) ' % counter
        counter += 1
        #last char
        output += word[-1] +  u'(%d) ' % counter
    else:
        output += word + u'(%d) ' % counter
        counter += 1

    print output

The error I am getting is:

  File "pyth_hinwp.py", line 22
    output += word[-1] +  u'(%d) ' % counter
                         ^
SyntaxError: invalid syntax

I know this question is something similar to what I have asked earlier, but since I am not able to successfully execute some of the answers given to me earlier hence I am kinda restructuring the question to the place where I am currently getting stuck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:00:21+00:00Added an answer on May 13, 2026 at 7:00 pm

    What is posted here does not have the error. Note that what is posted has TWO space characters between the + and the u in output += word[-1] + u'(%d) ' % counter. What is probably happening is that you have a whitespace character other than a space in there. A possibility is NBSP (U+00A0) aka “no-break space”. What SO does to format your code is likely to scrub away such things.

    Diagnosis: At the Python interactive prompt, type

    open("pyth_hinwp.py").readlines()[22-1]
    

    What do you see between the + and the u?

    Fix: in your editor, delete both characters between the + and the u. Insert a single space.

    By the way, with a syntax error, the problem is entirely within the named SOURCE file; the code has not been run (because it couldn’t be compiled) and so what is in your INPUT file has no bearing on the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This error is a nightmare, I have not been able to figure out why
I am not able to figure out why it is not tracing value for
I am not able to figure out how the graphs shown here are constructed?
I am stuck with a simple problem but not able to figure out the
In SQL Server 2005, I'm trying to figure out why I'm not able to
I can not figure out where my problem is but I am not able
I'm sure this is simple, but I'm not able to figure out why this
not able to get this, can someone help for this LINQ query? select col1,
My Java program fails with the following error on Windows. Exception in thread main
I'm trying to figure out why one of my objects does not seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.