I have a file with ids and information, like this:

```
1oMZgkoaz3o 2011-12-29T01:23:00.000Z 9 503 ApolloIsMyCoPilot
nUW1TomCSQg 2011-12-29T01:23:15.000Z 9 348 grea7stuff
tJuLnRrAcs0 2011-12-29T01:26:20.000Z 9 123 AdelGaming
tyi5g0mnPIs 2011-12-29T01:28:07.000Z 9 703 PreferredGaming

```

and I want to add a flag on some of the line, so if I have a dictionary

```
flags = {'1oMZgkoaz3o': flag1, 'tJuLnRrAcs0': flag2}

```

the result I want is 

```
1oMZgkoaz3o 2011-12-29T01:23:00.000Z 9 503 ApolloIsMyCoPilot flag1
nUW1TomCSQg 2011-12-29T01:23:15.000Z 9 348 grea7stuff
tJuLnRrAcs0 2011-12-29T01:26:20.000Z 9 123 AdelGaming flag2
tyi5g0mnPIs 2011-12-29T01:28:07.000Z 9 703 PreferredGaming

```

So I made this code

```
l = True
while l is True:
    a = f.readline()
    try a.split(' ')[0] in flags.iterkeys():
        f.seek(-1,1)
        f.write(' '+str(flags[a.split(' ')[0]])+'\n')
        del flags[a.split(' ')[0]]
    except IndexError:
        l = False

```

so, my Python code could be poor, but the problem is that with this code I'm replacing text, so the file is all messed up. How can I write without replacing? and if you have better ideas for the code, you are welcome...