A
Aahz
try: x = isinstance(s, int) and s or int(s, 0)
except ValueError: [handle invalid input]
Why aren't you using the ternary?
try: x = isinstance(s, int) and s or int(s, 0)
except ValueError: [handle invalid input]
Don't use 'is', use '=='.
BTW, ishex('') should return False.
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)
Wolfram said:ishex4=lambda s:not s.strip(string.hexdigits)
2010/1/15 Duncan Booth said:That's true, but since you were the one that pointed out they were all
broken I would have thought your solution should actually work.
I'm sure you'll agree that a longer solution that works trumps any short
but broken solution.
Duncan said:That's true, but since you were the one that pointed out they were all
broken I would have thought your solution should actually work.
I'm sure you'll agree that a longer solution that works trumps any short
but broken solution.
Only if you want to be inconsistent with other isFoo string functions:
False
Don't use 'is', use '=='.
BTW, ishex('') should return False.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.