This list of full of basic stuff though, and people who were referring to this would write insainly non-idiomatic Python, but hey, you gotta start somewhere.
When I went to doing Python full time (after having built stuff in it on and off for years) it took me a good 6 months before I was able to write idiomatic Python. That's with over 15 years development experience and actively reading lots of nice Python code to try to reach the same level.
Reading something like this reminds me of the gulf between, "can code in Python" and "writes nice code in Python".
What do you mean?
>>> u'0١߂३৪੫૬୭௮౯'.isdigit()
True
So it's not equivalent to matching [0-9]+, which some people might expect. It's quite nice i think, because apparently int() supports Unicode numeric characters too (i didn't know this): >>> int(u'0١߂३৪੫૬୭௮౯')
123456789I don't know if it is possible to construct an example where `isdigit` would return True but `int` would fail. It wouldn't surprise me, either way, but at the least the failure case isn't obvious.
The real problem is the converse `"1.23".isdigit()` returns False, where 1.23 is a number, so it doesn't 'check number'. And `int("-23")` works, but `"-23".isdigit()` is False. You could argue it 'checks non-negative integer'.
I happened upon a stack exchange answer a while back, accepted, that failed because of this bug.
In general the Python way to check if one thing can be converted into another is to try, and trap the error.
def isnumber(text):
try:
float(text)
except ValueError:
return False
else:
return TrueSolution: b == 0
`(a += b) == a + b` is not true, a += b is not an expression.
`str.is_digit()` doesn't 'check number', it checks if the string is entirely composed of unicode digit codepoints.
`dict(col)` doesn't work for a general collection `dict([1,2,3])` for example.
Are these really the things people forget the most coming from another language? Not try/raise/except/finally? Negative indices?
If it works, it works, good on you for making it (and making it look good), but in general, it seems to be a bit insubstantial.