I am trying to remove a sub string from a string in Python.
My data file contains a line of Koran, where each is marked with the poem and chapter number at the beginning of the string. I want to try to remove the first number and the second number and write it in one line in another text file. Here is an example of some lines of a txt file.
2 | 12 | Of a surety, those people who do mischief, but they feel (this) do not. 2 | 242 Thus Allah has made clear to you your signs: that you may understand. As you can see that there are many points in the poem and chapter, so calculating the number of spaces from the beginning of the string will not be enough. Is there a way to use the regular expression to try to remove the string as the first number (the poem) and the second number (chapters)?
The code for which I am writing this will try to write Arif, which is a poem and chapter string. An example of a line in the Arff file will be:
1,0,0,0,0,0,0,0,0,0,0,0,2,12 Where is the poem and chapter of the last two values.
Here you will have to write for each footer which I am interested and then I want to try to write poetry. Finally, using the regular expression to extract relevant substrings for each line, For the line in the verses
for the line: Topon for the item: Calculation = line quote (item) ARFF_FILE.write (str (count) + ",") # Here I use the regular expression I can use the desired substring # to extract poetry and chapters so write these at the end of a line in the arff file. ARFF_FILE.write ("\ n") I think the regular expression for the chapter number (number before the pipe) should be something like this, then to get the group (0) Use the first number of functions and
"^ (\ d +) \ | (\ d) \ |" Then the poem should be received by the regexp group (1)
, but I do not know how to implement it in Python. Anyone have any ideas? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ An answer question .
I have tried to apply your technique right now, but "index error: list index is going out of range. My code is
For: APF_Afile.write (parts [0] + ",") ARFF_FILE: parts = line.split ('|') count = line.count (item) ARFF_FILE.write (str (count) + ",") ARFF_FILE Write (part [1]) ARFF_FILE.write ("\ n")
If all of your lines are formatted like a | b> c , then you will not get any regs Not required, just split it.
Comments
Post a Comment