October 24th, 2013, 08:40 PM
How many digits in a string?
I need to return the number of digits and letters in any given string. I need to use a basic loop with no advanced techniques. think basic. Here is what i have but it wont work...help is
October 24th, 2013, 10:03 PM
Then again, I didn't test. Might not work at all.
moved the return statement.
You counted only the first character.
dig = 0
for char in sentence:
dig += 1
# for long sentences this might run faster because it involves less python interpretation and more c
digitCountDWL = lambda sentence: sum(sentence.count(d) for d in '0123456789')
[/code] are essential for python code and Makefiles!