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.