[Tutor] another better way to do this ?
Keith Winston
keithwins at gmail.com
Mon Jan 13 19:36:46 CET 2014
Yikes, Peter, that's scary. Wow.
On Mon, Jan 13, 2014 at 1:22 PM, Peter Otten <__peter__ at web.de> wrote:
> Peter Otten wrote:
>
>> Emile van Sebille wrote:
>>
>>> On 01/12/2014 12:21 PM, Peter Otten wrote:
>>>
>>>>>>> test("axbxc", "abc")
>>>> True
>>>>>>> test("abbxc", "abc")
>>>> False
>>>>
>>>> Is the second result desired?
>>>
>>> No -- the second should match -- you found a test case I didn't...
>>>
>>> def test(a,b):
>>> for ii in a:
>>> if ii not in b: a=a.replace(ii,"")
>>> while ii+ii in a: a=a.replace(ii+ii,ii)
>>> return b in a
>>>
>>> Show me another. :)
>>
>>>>> def test(a,b):
>> ... for ii in a:
>> ... if ii not in b: a=a.replace(ii,"")
>> ... while ii+ii in a: a=a.replace(ii+ii,ii)
>> ... return b in a
>> ...
>>>>> test("abac", "abc")
>> False
>
> In the mean time here is my candidate:
>
> def test(a, b):
> a = iter(a)
> return all(c in a for c in b)
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Keith
More information about the Tutor
mailing list