Writing a string.ishex function

MRAB python at mrabarnett.plus.com
Thu Jan 14 21:00:38 EST 2010


Wolfram Hinderer wrote:
> On 14 Jan., 19:48, MRAB <pyt... at mrabarnett.plus.com> wrote:
>> Arnaud Delobelle wrote:
>>> "D'Arcy J.M. Cain" <da... at druid.net> writes:
>>>> On Thu, 14 Jan 2010 09:07:47 -0800
>>>> Chris Rebert <c... at rebertia.com> wrote:
>>>>> Even more succinctly:
>>>>> def ishex(s):
>>>>>     return all(c in string.hexdigits for c in s)
>>>> I'll see your two-liner and raise you.  :-)
>>>> ishex = lambda s: all(c in string.hexdigits for c in s)
>>> I'see your one-liner and raise you by four characters :o)
>>> ishex1 = lambda s: all(c in string.hexdigits for c in s) # Yours
>>> ishex2 = lambda s: not(set(s)-set(string.hexdigits))     # Mine
>> I raise you one character:
>>
>> ishex2 = lambda s: not(set(s)-set(string.hexdigits))     # Yours
>> ishex3 = lambda s: not set(s)-set(string.hexdigits)      # Mine
>>
>> I could actually go three better:
>>
>> ishex3=lambda s:not set(s)-set(string.hexdigits)
>>
>> :-)
>>
> 
> ishex4=lambda s:not s.strip(string.hexdigits)

Doh!



More information about the Python-list mailing list