Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.

Please note that the string does not contain any non-printable characters.

Example:

Input: "Hello, my name is John"
Output: 5

Difficulty: EASY
Starter code: class Solution:
    def countSegments(self, s: str) -> int:
        

Solutions:
class Solution:

	def countSegments(self, s):
		return len(s.split())


class Solution:

	def countSegments(self, s):
		count = 0
		finished = True
		for c in s:
			if finished:
				if c is ' ':
					continue
				else:
					finished = False
					count += 1
			elif c is ' ':
				finished = True
			else:
				continue
		return count


class Solution:

	def countSegments(self, s):
		c = 0
		l = s.split(' ')
		for i in l:
			if i != '':
				c += 1
		return c


class Solution:

	def countSegments(self, s):
		if len(s) == 0:
			return 0
		seen_character = False
		count = 0
		for char in s:
			if seen_character and char == ' ':
				count += 1
				seen_character = False
			elif seen_character == False and char != ' ':
				seen_character = True
		if seen_character:
			count += 1
		return count