Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74880 > unrolled thread

Re: stripping (from item in list)

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-07-20 13:15 -0400
Last post2014-07-20 13:15 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: stripping (from item in list) Terry Reedy <tjreedy@udel.edu> - 2014-07-20 13:15 -0400

#74880 — Re: stripping (from item in list)

FromTerry Reedy <tjreedy@udel.edu>
Date2014-07-20 13:15 -0400
SubjectRe: stripping (from item in list)
Message-ID<mailman.12097.1405876575.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web