avatar Bite 115. Count leading spaces

A small but interesting Bite: given a string with leading indent spacing, calculate the amount of space (literal space, not tab or newline) characters:

  • 'string  ' -> 0 (we only care about leading spacing)
  • '  string' -> 2
  • '    string' -> 4
  • etc...

This can be done in many ways so once done we encourage you to go into the Bite forum (Discussion tab that appears upon solving the Bite) to discuss your solution with fellow Pythonistas ... Have fun!

Login and get coding
go back Beginner level
Bitecoin 2X

496 out of 497 users completed this Bite.
Will you be Pythonista #497 to crack this Bite?
Resolution time: ~20 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 2.83 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help