Given a string, The task is to count the number of alphabets present in the string.
Example 1:
Input:
S = "adjfjh23"
Output: 6
Explanation: only last 2 are not 
alphabets.
Example 2:
Input:
S = "n0ji#k$"
Output: 4
Explanation: #, $, 0 are not alphabets.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function Count() which takes the string S as inputs and returns alphabets count.
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ |S| ≤ 10^{5}
S contains only upper and lower case alphabets, digits and '#', '!', '$', '&' only.

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:



    def Count(self, S):

        # code here

Solutions:
class Solution:

	def Count(self, S):
		import re
		x = re.findall('[a-zA-Z]+', S)
		x = ''.join(x)
		return len(x)


import string

class Solution:

	def Count(self, S):
		count = 0
		for i in S:
			if i in string.ascii_letters:
				count += 1
		return count


class Solution:

	def Count(self, S):
		c = 0
		for i in S:
			if i.isalpha() == True:
				c += 1
		return c


class Solution:

	def Count(self, S):
		b = 0
		a = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l']
		for i in S:
			if i.lower() in a:
				b = b + 1
		return b


class Solution:

	def Count(self, S):
		cnt = 0
		for i in S:
			if i.isalpha():
				cnt += 1
		return cnt


class Solution:

	def Count(self, S):
		count = 0
		for i in S:
			if ord(i) >= 97 and ord(i) <= 122 or (ord(i) >= 65 and ord(i) <= 90):
				count += 1
		return count


class Solution:

	def Count(self, s):
		count = 0
		for i in s:
			if i.isalpha():
				count += 1
		return count


class Solution:

	def Count(self, S):
		counter = 0
		for i in S:
			if ord(i) in range(65, 91) or ord(i) in range(97, 123):
				counter += 1
		return counter


class Solution:

	def Count(self, S):
		k = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		c = 0
		for i in S:
			if i in k:
				c += 1
		return c


class Solution:

	def Count(self, S):
		return sum((x.isalpha() for x in S))


class Solution:

	def Count(self, S):
		count = 0
		alphabets = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		for i in S:
			if i in alphabets:
				count += 1
		return count


class Solution:

	def Count(self, S):
		list1 = [i for i in S if not i.isalpha()]
		return len(S) - len(list1)


class Solution:

	def Count(self, S):
		cnt = 0
		for x in S:
			if 'a' <= x <= 'z' or 'A' <= x <= 'Z':
				cnt += 1
		return cnt


class Solution:

	def Count(self, S):
		count = 0
		for c in S:
			if c.isalpha():
				count += 1
		return count


class Solution:
	count = 0

	def Count(self, S):
		self.S = S
		count = 0
		for i in S:
			if i >= 'a' and i <= 'z':
				count = count + 1
			elif i >= 'A' and i <= 'Z':
				count = count + 1
		return count


class Solution:

	def Count(self, S):
		c = 0
		S = S.lower()
		a = 'qwertyuiopasdfghjklzxcvbnm'
		for i in S:
			if i in a:
				c += 1
		return c


class Solution:

	def Count(self, S):
		count = 0
		for i in range(len(S)):
			if S[i].isalpha():
				count += 1
		return count


class Solution:

	def Count(self, S):
		count = 0
		for i in S:
			if i.isalpha():
				count += 1
			else:
				pass
		return count


class Solution:

	def Count(self, S):
		count = 0
		for i in S:
			if ord(i) in range(65, 92) or ord(i) in range(97, 123):
				count += 1
		return count


class Solution:

	def Count(self, S):
		l = []
		for i in S:
			if i.isalpha():
				l.append(i)
		return len(l)


class Solution:

	def Count(self, S):
		S.lower()
		count = 0
		for i in S:
			if 'a' <= i <= 'z' or 'A' <= i <= 'Z':
				count = count + 1
		return count


class Solution:

	def Count(self, s):
		c = 0
		for i in s:
			if i >= 'a' and i <= 'z':
				c += 1
			elif i >= 'A' and i <= 'Z':
				c += 1
		return c


class Solution:

	def Count(self, S):
		res = 0
		for s in S:
			if s.isalpha():
				res += 1
		return res


class Solution:

	def Count(self, S):
		cnt = 0
		a = list(S)
		for i in range(len(a)):
			if ord(a[i]) >= 97 and ord(a[i]) < 123 or (ord(a[i]) >= 65 and ord(a[i]) < 92):
				cnt += 1
		return cnt


class Solution:

	def Count(self, S):
		count = 0
		for e in S:
			if e >= 'a' and e <= 'z' or (e >= 'A' and e <= 'Z'):
				count += 1
		return count


class Solution:

	def Count(self, S):
		ans = 0
		for i in S:
			if ord(i) <= ord('z') and ord(i) >= ord('a') or (ord(i) <= ord('Z') and ord(i) >= ord('A')):
				ans += 1
		return ans


class Solution:

	def Count(self, S):
		c = 0
		S = S.lower()
		for i in S:
			if i in 'abcdefghijklmnopqrstuvwxyz':
				c += 1
		return c


class Solution:

	def Count(self, S):
		c = 0
		for i in range(len(S)):
			if S[i] >= 'A' and S[i] <= 'Z' or (S[i] >= 'a' and S[i] <= 'z'):
				c = c + 1
		return c


class Solution:

	def Count(self, S):
		lst = list(S)
		l = len(lst)
		count = 0
		for i in range(l):
			if 65 <= ord(lst[i]) <= 122:
				count = count + 1
		return count


class Solution:

	def Count(self, S):
		c = 0
		for i in S:
			if ord(i) in range(97, 123) or ord(i) in range(64, 91):
				c = c + 1
		return c


class Solution:

	def Count(self, S):
		res = len([ele for ele in S if ele.isalpha()])
		return res


class Solution:

	def Count(self, s):
		out = ''
		for i in range(len(S)):
			if int(ord(s[i])) >= 65 and int(ord(s[i])) <= 90 or (int(ord(s[i])) >= 97 and int(ord(s[i])) <= 122):
				out += s[i]
		return len(out)


class Solution:

	def Count(self, S):
		count = 0
		for char in S:
			count += char.isalpha()
		return count


class Solution:

	def Count(self, S):
		count = 0
		S = S.lower()
		alphabet = list('abcdefghijklmnopqrstuvwxyz')
		for i in S:
			if i in alphabet:
				count += 1
		return count


class Solution:

	def Count(self, S):
		ans = 0
		for ele in S:
			if ele.isalpha():
				ans += 1
		return ans


class Solution:

	def Count(self, S):
		count = 0
		for char in S:
			if char.isalpha() is True:
				count += 1
		return count


class Solution:

	def Count(self, S):
		count = 0
		l = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		for each in S:
			if each in l:
				count += 1
		return count


class Solution:

	def Count(self, S):
		d1 = {}
		count = 0
		for i in S:
			if i.isupper() or i.islower():
				d1[i] = d1.get(i, 0) + 1
		for i in d1:
			count += d1.get(i)
		return count


class Solution:

	def Count(self, S):
		l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '#', '!', '$', '&']
		s = 0
		for i in range(len(S)):
			if S[i] not in l:
				s += 1
		return s


class Solution:

	def Count(self, s):
		a_count = 0
		al = set('abcdefghijklmnopqrstuvwxyzABCDEFGHJIKLMNOPQRSTUVWXYZ')
		for i in range(len(s)):
			if s[i] in al:
				a_count += 1
		return a_count


class Solution:

	def Count(self, S):
		A = []
		for a in range(len(S)):
			value1 = ord(S[a])
			if value1 > 64 and value1 < 123 and (value1 not in (91, 96)):
				A.append(S[a])
		return len(A)


class Solution:

	def Count(self, S):
		p = ''
		for i in S:
			if i.isalpha():
				p = p + i
			else:
				pass
		return len(p)


class Solution:

	def Count(self, S):
		p = ''
		q = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		for i in S:
			if i in q:
				p = p + i
			else:
				pass
		return len(p)


class Solution:

	def Count(self, S):
		val = 0
		summ = 0
		for i in S:
			if i.isalpha():
				val += 1
			else:
				summ += 1
		return val


class Solution:

	def Count(self, S):
		arr = list(S)
		ans = 0
		for e in arr:
			if e.isalpha():
				ans += 1
		return ans