Re: something about split()???

2012-08-21 Thread mingqiang hu
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 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 wrote:
>
>> Ramchandra Apte wrote:
>>
>>> (Much) more Pythonic solution:
>>> >>> filter(None,"|".split("|"))
>>>
>>> On 14 August 2012 15:14, Andreas Tawn >> andreas.tawn@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
>>>
>>>
>>>  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"
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asking

2012-08-22 Thread mingqiang hu
I mean any of "a","b","c" in string "adfbdfc"  makes the statement true,can
I not use a function?  suppose I got lots of substring let's say
s1="a",s2="b",s3="c" ...,not wrap them as a tuple or a list , just make the
statement as simple as possible to check if any of the value is the
substring of S="fasfasdfgbefve".

On Wed, Aug 22, 2012 at 1:17 PM, Dave Angel  wrote:

> On 08/22/2012 12:17 AM, Ian Foote wrote:
> > Oops, hopefully this with indent correctly:
> >
> > def all_in(string, substrings):
> > for substring in substrings:
> > if substring not in string:
> > return False
> > return True
>
> The POP's question was ambiguous (did he want to match any of the
> substrings, or all of the substrings), but his example code:
>
>
> ("a" in "adfbdfc")  or ( "b" in "adfbdfc") or ("c" in "adfbdfc" )
>
> implements the opposite sense of what you have.  So perhaps he'd want:
>
>
> def any_in(string, substrings):
> for substring in substrings:
> if substring in string:
>   return True:
> return False
>
>
> --
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list