Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74880
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: stripping (from item in list) |
| Date | 2014-07-20 13:15 -0400 |
| References | <CAHXoDSCZsCUFC9uyFkHWGMtJjvisZN5j79BHykqxqtxX5tox4Q@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12097.1405876575.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: stripping (from item in list) Terry Reedy <tjreedy@udel.edu> - 2014-07-20 13:15 -0400
csiph-web