something about split()???

mingqiang hu humingqiang5262131 at gmail.com
Tue Aug 21 23:43:59 EDT 2012


why filter is bad when use lambda ?actually I think I can use lambda like
this: filter(lambda x:x==None,"|",split("|"))

On Wed, Aug 15, 2012 at 1:33 PM, Ramchandra Apte <maniandram01 at gmail.com>wrote:

> filter is bad when you use lambda with it
> there are (good) cases for filter
>
>
> On 14 August 2012 22:39, Jean-Michel Pichavant <jeanmichel at sequans.com>wrote:
>
>> Ramchandra Apte wrote:
>>
>>> (Much) more Pythonic solution:
>>> >>> filter(None,"|".split("|"))
>>>
>>> On 14 August 2012 15:14, Andreas Tawn <andreas.tawn at ubisoft.com <mailto:
>>> andreas.tawn at ubisoft.**com <andreas.tawn at ubisoft.com>>> 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<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<http://pylint-messages.wikidot.com/messages:w0141>
>> "les goûts et les couleurs ne se discutent pas"
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120822/0dfdeebb/attachment.html>


More information about the Python-list mailing list