Re: something about split()???

Discussion in 'Python' started by Jean-Michel Pichavant, Aug 14, 2012.

  1. Ramchandra Apte wrote:
    > (Much) more Pythonic solution:
    > >>> filter(None,"|".split("|"))

    >
    > On 14 August 2012 15:14, Andreas Tawn <
    > <mailto:>> wrote:
    >
    > > I have a question about the split function? surpose a = "|",and

    > when I use a.split("|") , I got the list
    > > ['"",""] ,but I want to get the empty list,what should I do ?

    >
    > Something like...
    >
    > >>> [x for x in "|".split("|") if x]

    > []
    >
    > Cheers,
    >
    > Drea
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >

    A pythonic answer would be bottom-posted :p

    JM


    PS : pylint raises a low warning about *filter* being non pythonic,
    http://pylint-messages.wikidot.com/messages:w0141
    "les goƻts et les couleurs ne se discutent pas"
     
    Jean-Michel Pichavant, Aug 14, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    490
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    735
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    236
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    274
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    702
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page