In article ,
MRAB wrote:
>D'Arcy J.M. Cain wrote:
>> On Thu, 14 Jan 2010 07:52:58 -0800 (PST)
>> chandra wrote:
>>> Folks,
>>>
>>> I am new to Python and could not find a function along the lines of
>>
>> Welcome.
>>
>>> string.ishex in Python. There is however, a string.hexdigits constant
>>> i
On Fri, 15 Jan 2010 00:53:51 +, Steven D'Aprano wrote:
> On Thu, 14 Jan 2010 18:36:12 +, MRAB wrote:
>> BTW, ishex('') should return False.
>
>
> Only if you want to be inconsistent with other isFoo string functions:
>
''.isalpha()
> False
I said what???
Sorry MRAB, what I wrote
Duncan Booth wrote:
MRAB wrote:
Duncan Booth wrote:
MRAB wrote:
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(st
2010/1/15 Duncan Booth :
> MRAB wrote:
>
>> Duncan Booth wrote:
>>> MRAB wrote:
>>>
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 b
MRAB wrote:
> Duncan Booth wrote:
>> MRAB wrote:
>>
>>> 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 s
Wolfram Hinderer wrote:
On 14 Jan., 19:48, MRAB wrote:
Arnaud Delobelle wrote:
"D'Arcy J.M. Cain" writes:
On Thu, 14 Jan 2010 09:07:47 -0800
Chris Rebert 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. :-)
On 14 Jan., 19:48, MRAB wrote:
> Arnaud Delobelle wrote:
> > "D'Arcy J.M. Cain" writes:
>
> >> On Thu, 14 Jan 2010 09:07:47 -0800
> >> Chris Rebert wrote:
> >>> Even more succinctly:
>
> >>> def ishex(s):
> >>> return all(c in string.hexdigits for c in s)
> >> I'll see your two-liner and rai
On Thu, 14 Jan 2010 18:36:12 +, MRAB wrote:
>> And here are your unit tests. Every line should print "True".
>>
>> print ishex('123') is True
>> print ishex('abc') is True
>> print ishex('xyz') is False
>> print ishex('0123456789abcdefABCDEF') is True
>> print ishex('0123456789abcdefABCDEFG
In article ,
D'Arcy J.M. Cain wrote:
>
>try: x = isinstance(s, int) and s or int(s, 0)
>except ValueError: [handle invalid input]
Why aren't you using the ternary?
--
Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/
"If you think it's expensive to hire a professiona
Arnaud Delobelle wrote:
MRAB writes:
Arnaud Delobelle wrote:
"D'Arcy J.M. Cain" writes:
On Thu, 14 Jan 2010 09:07:47 -0800
Chris Rebert 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 = lambd
On 1/14/2010 12:44 PM, D'Arcy J.M. Cain wrote:
On Thu, 14 Jan 2010 09:07:47 -0800
Chris Rebert 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)
T
MRAB writes:
> Arnaud Delobelle wrote:
>> "D'Arcy J.M. Cain" writes:
>>
>>> On Thu, 14 Jan 2010 09:07:47 -0800
>>> Chris Rebert 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. :-)
>>>
>>>
On 08:15 pm, da...@druid.net wrote:
On 14 Jan 2010 19:19:53 GMT
Duncan Booth wrote:
> 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(strin
On Thu, 14 Jan 2010 18:36:12 +
MRAB wrote:
> > print ishex('123') is True
> > print ishex('abc') is True
> > print ishex('xyz') is False
> > print ishex('0123456789abcdefABCDEF') is True
> > print ishex('0123456789abcdefABCDEFG') is False
> >
> Don't use 'is', use '=='.
Why? There is only o
On 14 Jan 2010 19:19:53 GMT
Duncan Booth wrote:
> > 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)
>
> But non
Duncan Booth wrote:
MRAB wrote:
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)
But none of those
Phlip wrote:
MRAB wrote:
BTW, ishex('') should return False.
So should int('')!
Did you mean isint('') ?
JM
--
http://mail.python.org/mailman/listinfo/python-list
MRAB wrote:
> 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)
But none of those pass you
Phlip wrote:
MRAB wrote:
BTW, ishex('') should return False.
So should int('')!
Why?
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle wrote:
"D'Arcy J.M. Cain" writes:
On Thu, 14 Jan 2010 09:07:47 -0800
Chris Rebert 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
MRAB wrote:
BTW, ishex('') should return False.
So should int('')!
--
http://mail.python.org/mailman/listinfo/python-list
D'Arcy J.M. Cain wrote:
On Thu, 14 Jan 2010 07:52:58 -0800 (PST)
chandra wrote:
Folks,
I am new to Python and could not find a function along the lines of
Welcome.
string.ishex in Python. There is however, a string.hexdigits constant
in the string module. I thought I would enhance the exis
"D'Arcy J.M. Cain" writes:
> On Thu, 14 Jan 2010 09:07:47 -0800
> Chris Rebert 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's
Iain King wrote:
> better would be:
> def ishex(s):
> for c in s:
> if c not in string.hexdigits:
> return False
> return True
Even more elegant and probably a faster solutions:
---
from string import hexdigits
hexdigits = frozenset(hexdigits)
def ishex(s):
return
On Thu, 14 Jan 2010 09:07:47 -0800
Chris Rebert 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)
--
D'Arcy J.M. Cain | Democracy is
chandra wrote:
> On Jan 15, 12:22 am, "D'Arcy J.M. Cain" wrote:
>
>> Just return False once you find a non-hex digit.
>>
>> def ishex(s):
>> for c in s:
>> if not c in string.hexdigits: return False
>>
>> return True
>>
>> And here are your unit tests. Every line should print "True".
>>
On Thu, Jan 14, 2010 at 8:14 AM, Iain King wrote:
> On Jan 14, 3:52 pm, chandra wrote:
>> Folks,
>>
>> I am new to Python and could not find a function along the lines of
>> string.ishex in Python. There is however, a string.hexdigits constant
>> in the string module. I thought I would enhance th
On Jan 15, 12:22 am, "D'Arcy J.M. Cain" wrote:
> Just return False once you find a non-hex digit.
>
> def ishex(s):
> for c in s:
> if not c in string.hexdigits: return False
>
> return True
>
> And here are your unit tests. Every line should print "True".
>
> print ishex('123') is True
On Thu, 14 Jan 2010 07:52:58 -0800 (PST)
chandra wrote:
> Folks,
>
> I am new to Python and could not find a function along the lines of
Welcome.
> string.ishex in Python. There is however, a string.hexdigits constant
> in the string module. I thought I would enhance the existing modlue
> but a
On Jan 14, 3:52 pm, chandra wrote:
> Folks,
>
> I am new to Python and could not find a function along the lines of
> string.ishex in Python. There is however, a string.hexdigits constant
> in the string module. I thought I would enhance the existing modlue
> but am unsure how I should go about it
30 matches
Mail list logo