Question: I'm trying to delete a specific line that contains a specific string.

I've a file called **numbers.txt** with the following content:

> 
> peter  
> 
>  tom  
> 
>  tom1  
> 
>  yan  
> 
> 
> 
> 

What I want to delete is that **tom** from the file, so I made this function:

```
def deleteLine():
fn = 'numbers.txt'
f = open(fn)
output = []
for line in f:
    if not "tom" in line:
        output.append(line)
f.close()
f = open(fn, 'w')
f.writelines(output)
f.close()

```

The output is:

> 
> peter  
> 
>  yan  
> 
> 
> 
> 

As you can see, the problem is that the function delete **tom** and **tom1**, but I don't want to delete **tom1**. I want to delete just **tom**. This is the output that I want to have:

> 
> peter  
> 
>  tom1  
> 
>  yan  
> 
> 
> 
> 

Any ideas to change the function to make this correctly?

Answer: 
Just for fun, here's a two-liner to do it.

```
lines = filter(lambda x:x[0:-1]!="tom", open("names.txt", "r"))
open("names.txt", "w").write("".join(lines))

```

Challenge: someone post a one-liner for this.

You could also use the fileinput module to get arguably the most readable result:

```
import fileinput
for l in fileinput.input("names.txt", inplace=1):
    if l != "tom\n": print l[:-1]

```
I'm new in programing and python (a few months)... this is my solution:

```
import fileinput

c = 0 # counter
for line in fileinput.input("korrer.csv", inplace=True, mode="rb"):
    # the line I want to delete
    if c == 3: 
        c += 1
        pass
    else:
        line = line.replace("\n", "")
        print line
        c +=1

```

I'm sure there is a simpler way, just it's an idea. (my English it's not very good looking!!)