how to delete a certain line in a string
<p>I'm having real trouble finding the relevant information for this answer, so far I have this code:</p>

<pre><code>test = ("")
file_content = ("")
reset = 0
import os


file = open("repeated names.txt",'r', encoding="utf-8-sig")

from collections import Counter
wordcount = Counter(file.read().split())

for item in wordcount.items():
    test = ("{}, = {}".format(*item))
    short_string = test
    file_content+=short_string
    file_content+=("\n")

try:
    f = open ("storage.xls", 'a')    # storing data befor change
    f.write (file_content)
    f.close()
except PermissionError:
    print ("NOTICE:")
    print ("""this file cannot be opened/save, due to it being open at the moment, please close the file before running the programe again, thank-you.""")
    time.sleep (1)

find = (" = 4")
test3 = ("")
test5 = ("")

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

for line in StringIO(file_content):
        test2 = (line.strip())
        if find in test2:
            test3 +=test2
            test3 +=("\n")



print ("these are the names that have appered more than four times")
print (test3)

file_content_V3 = ("")
file_content_V4 = ("")

with open ("repeated results.txt", 'r') as r: #the results include a name with a ',' after it like this: 'name,'
    for line in sorted(r):
        if "..." in line:
            pass
        else :
            short_string = (line)
            file_content_V3+=short_string
            file_content_V3+=("...")
            file_content_V3+=("\n")

test4 = test3.replace(' = 4','')
print (test4)

# i would only like to have the first 3 results, so i have kept it to 4, so it will delete the last one.

one = 0
two = 1
three = 0

for line in StringIO(file_content_V3):
    one = one+two

for line in StringIO(test4):
    three = three+two

one = (one - two)

print (one)
print (three)

num = 0
numV2 = 0
yes = 0

delete = ("")

while True:
    manager = (file_content_V3.splitlines()[num])
    print (manager)
    while True:
        if reset == 0:
            findV2 = (test4.splitlines()[numV2])
            print (findV2)
            if findV2 in manager:
                print ("yes")
                yes = (yes+1)

                # code that is suppose to go here:
                # code that deletes the line 'numV2' from string 'test4'.
                # code that deletes the line 'num' from string 'file_content_V3'.

                delete += str(num)
                delete+= ("\n")
                reset = 1
                num = (num+1)
            else:
                print (numV2)
                numV2 = (numV2 + 1)
                print ("reset intiates")
                reset = 1
                if numV2 == three:
                    reset = 1
                    numV2 = 0
                    num = (num + 1)
                    print ("hard reset initiated")

        if reset == 1:
            print ("working")
            reset = 0
            if num == one:
            reset = 2
            break

        if reset == 2:
            break
        break

    if reset == 2:
        break

print ("i am out of all loops")
print (num, "", one)
print (yes)
print (delete)

print (test4)

# it may be hard to understand at this point, as I have a lot of testing to do to make sure it works stably (had some flaws here and there). 
</code></pre>

<p>The code is used to sort out results alphabetically, and to only have three of the latest results. so far, I have got it to be able to say 'yes' when ever it finds a repeat, but then I would like to have a code that can delete that line (or a code that deletes certain lines in a string in general).</p>

<p>I am trying to figure out how to delete a line from a string using the line numbers, (not file, as there have been a lot of string transfers from the original string). After a dozen of searches, I am no where close enough to my answer. </p>

<p>it will be really helpful if someone helped me what code can delete lines in strings, by giving a a number for which line. Note: I cannot download third party modules, sorry but its only those modules that come with python, pre downloaded...</p>

<p>so can any one help me out, thank-you, links to other web pages will also be helpful.</p>