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


Groups > comp.lang.python > #108022

Re: Best way to clean up list items?

From Stephen Hansen <me+python@ixokai.io>
Newsgroups comp.lang.python
Subject Re: Best way to clean up list items?
Date 2016-05-02 10:25 -0700
Message-ID <mailman.325.1462209932.32212.python-list@python.org> (permalink)
References <ng7v9d$ld8$1@dont-email.me> <1462209930.1313497.595817481.73635112@webmail.messagingengine.com>

Show all headers | View raw


On Mon, May 2, 2016, at 09:33 AM, DFS wrote:
> Have: list1 = ['\r\n   Item 1  ','  Item 2  ','\r\n  ']

I'm curious how you got to this point, it seems like you can solve the
problem in how this is generated.

> Want: list1 = ['Item 1','Item 2']

That said:

list1 = [t.strip() for t in list1 if t and not t.isspace()]

-- 
Stephen Hansen
  m e @ i x o k a i . i o

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to clean up list items? DFS <nospam@dfs.com> - 2016-05-02 12:33 -0400
  Re: Best way to clean up list items? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-02 19:57 +0300
    Re: Best way to clean up list items? justin walters <walters.justin01@gmail.com> - 2016-05-02 10:10 -0700
    Re: Best way to clean up list items? DFS <nospam@dfs.com> - 2016-05-02 14:06 -0400
      Re: Best way to clean up list items? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-02 21:27 +0300
        Re: Best way to clean up list items? DFS <nospam@dfs.com> - 2016-05-02 15:04 -0400
  Re: Best way to clean up list items? Stephen Hansen <me+python@ixokai.io> - 2016-05-02 10:25 -0700
    Re: Best way to clean up list items? DFS <nospam@dfs.com> - 2016-05-02 14:09 -0400
      Re: Best way to clean up list items? Stephen Hansen <me+python@ixokai.io> - 2016-05-02 11:23 -0700
  Re: Best way to clean up list items? Peter Otten <__peter__@web.de> - 2016-05-02 19:30 +0200

csiph-web