stripping (from item in list)

Terry Reedy tjreedy at
Sun Jul 20 19:15:58 CEST 2014

On 7/20/2014 5:40 AM, Martin S wrote:

> while c >=0:
>          x=games[c][0]
>          if x=="#":
>              del games[c] #This removes the comments from the file parsed
>          else:
>              games[c].rstrip('\n') #This does nothing, expected to remove \n

Chris already pointed out error here.

>          c=c-1
>      # Now we have a list with only proper lines

I believe what you are aiming for is

games = [line.rstrip('\n') for line in games if line[0] != '#']

Terry Jan Reedy

More information about the Python-list mailing list