Just wrote this function…
def nrofleadingchars(stringtotest, testchar='\t'):
count = 0
for c in stringtotest:
if c == testchar:
count = count + 1
else:
return count
return count
However does not feel pythonic ‘enough’, suggestions?
In my opinion the code is straightforward, so you should prefer it to some unreadable mess.
I would just shorten it a bit: