Given a string str, convert the first letter of each word in the string to uppercase. 
Example 1:
Input:
str = "i love programming"
Output: "I Love Programming"
Explanation:
'I', 'L', 'P' are the first letters of 
the three words.
Your Task:  
You dont need to read input or print anything. Complete the function transform() which takes s as input parameter and returns the transformed string.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N) to store resultant string  
Constraints:
1 <= N <= 10^{4}
The original string str only consists of lowercase alphabets and spaces to separate words.

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:
    def transform(self, s):
        # code here

Solutions:
import string

class Solution:

	def transform(self, s):
		return string.capwords(s)


class Solution:

	def transform(self, s):
		return s.title()


class Solution:

	def transform(self, s):
		l = s.split()
		res = []
		for i in l:
			if len(i) == 1:
				i = i.upper()
				res.append(i)
			else:
				i = i[0].upper() + i[1:]
				res.append(i)
		return ' '.join(res)


class Solution:

	def transform(self, s):
		a = s.split()
		b = []
		c = []
		for i in range(len(a)):
			b.append(a[i][0].upper())
			c.append(b[i] + a[i][1:])
		return ' '.join(c)


class Solution:

	def transform(self, s):
		newstr = ''
		for i in range(len(s)):
			if s[i - 1] == ' ' or i == 0:
				n = ord(s[i]) - 32
				newstr = newstr + chr(n)
			else:
				newstr = newstr + s[i]
		return newstr


class Solution:

	def transform(self, s):
		return ' '.join([i[0].upper() + i[1:] for i in s.split()])


class Solution:

	def transform(self, s):
		word = s.split()
		c = [s.capitalize() for s in word]
		return ' '.join(c)


class Solution:

	def transform(self, s):
		r = s[0].upper()
		for i in range(1, len(s)):
			if s[i - 1] == ' ':
				r += s[i].upper()
			else:
				r += s[i]
		return r


class Solution:

	def transform(self, s):
		res = s.split()
		res = [i.title() for i in res]
		l = ' '.join(res)
		return l


class Solution:

	def transform(self, s):
		s2 = s.split(' ')
		res = ''
		for i in s2:
			res = res + i.capitalize() + ' '
		return res


class Solution:

	def transform(self, s):
		s = s.lower()
		words = s.split(' ')
		transformed_words = [word.capitalize() for word in words]
		transformed_string = ' '.join(transformed_words)
		return transformed_string


class Solution:

	def transform(self, s):
		res = ''
		s = s.capitalize()
		isSpace = False
		for e in s:
			ele = e
			if isSpace:
				isSpace = False
				res = res + e.upper()
			else:
				res = res + e
			if ele == ' ':
				isSpace = True
		return res


class Solution:

	def transform(self, s):
		l = s.split()
		for i in range(len(l)):
			l[i] = l[i].title()
		return ' '.join(l)


class Solution:

	def transform(self, s):
		result = []
		str = s.split()
		for i in str:
			if len(i) == 1:
				result.append(i.upper())
			if len(i) > 1:
				result.append(i[0].upper() + i[1:])
		return ' '.join(result)


class Solution:

	def transform(self, s):
		l = s.split()
		str_upper = ''
		for i in l:
			str_upper = str_upper + i.capitalize() + ' '
		return str_upper


class Solution:

	def transform(self, s):
		string = s.split(' ')
		list1 = []
		for i in string:
			result = i.capitalize()
			list1.append(result)
		string = ','.join(list1)
		result = string.replace(',', ' ')
		return result


class Solution:

	def transform(self, s):
		s = list(s)
		s[0] = s[0].capitalize()
		for i in range(len(s)):
			if s[i] == ' ':
				s[i + 1] = s[i + 1].capitalize()
		s = ''.join(s)
		return s


class Solution:

	def transform(self, s):
		str_list = s.split()
		str = ''
		for i in str_list:
			str += i.capitalize() + ' '
		return str


class Solution:

	def transform(self, s):
		ans = ''
		for i in s:
			return s.title()


class Solution:

	def transform(self, s):
		s = ' ' + s
		s = list(s)
		for i in range(len(s)):
			if s[i] == ' ':
				s[i + 1] = s[i + 1].upper()
		s = s[1:]
		s = ''.join(s)
		return s


class Solution:

	def transform(self, s):
		ans = ''
		ans += chr(ord(s[0]) - 32)
		for i in range(0, len(s) - 1):
			if s[i] == ' ':
				ans += chr(ord(s[i + 1]) - 32)
			else:
				ans += s[i + 1]
		return ans


class Solution:

	def transform(self, s):
		list_s = s.split()
		result = ''
		for each in list_s:
			result += each.capitalize() + ' '
		return result


class Solution:

	def transform(self, s):
		lst = s.split(' ')
		res = []
		for i in lst:
			res.append(i.lower().capitalize())
		S = ' '.join(res)
		return S


class Solution:

	def transform(self, s):
		Words = s.split(' ')
		words = []
		for word in Words:
			words.append(word.lower().capitalize())
		return ' '.join(words)


class Solution:

	def transform(self, s):
		t = s.split()
		p = [r.capitalize() for r in t]
		return ' '.join(p)


class Solution:

	def transform(self, s):
		words = list(s.split(' '))
		w = []
		for i in range(len(words)):
			w += [words[i].capitalize()]
		return ' '.join(w)


class Solution:

	def transform(self, s):
		ans = ''
		for i in range(0, len(s), 1):
			if i == 0:
				ans += s[i].upper()
			elif (ord(s[i]) >= ord('a') and ord(s[i]) <= ord('z')) and ord(s[i - 1]) == ord(' '):
				ans += s[i].upper()
			else:
				ans += s[i]
		return ans


class Solution:

	def transform(self, s):
		inp_list = list(s.split(' '))
		out_list = []
		for word in inp_list:
			temp_list = list(word)
			temp_list[0] = temp_list[0].upper()
			out_list.append(''.join(temp_list))
		return ' '.join(out_list)


class Solution:

	def transform(self, s):
		rs = s.split()
		result = ''
		for i in rs:
			result += i.capitalize() + ' '
		return result


class Solution:

	def transform(self, s):
		ls = []
		lt = list(s)
		ls.append(lt[0].upper())
		i = 1
		while i < len(lt):
			if lt[i] == ' ':
				ls.append(lt[i])
				ls.append(lt[i + 1].upper())
				i = i + 2
			else:
				ls.append(lt[i])
				i = i + 1
		return ''.join(ls)


class Solution:

	def transform(self, s):
		l = []
		for i in s.split():
			l.append(i.capitalize())
		return ' '.join(l)


class Solution:

	def transform(self, s):
		words = s.split()
		new_str = []
		final_str = ''
		for i in words:
			new_str.append(i.capitalize())
		for j in new_str:
			final_str = final_str + j + ' '
		return final_str


class Solution:

	def transform(self, s):
		S = str(s)
		return S.title()


class Solution:

	def transform(self, s):
		s = s.split()
		S = ''
		for i in s:
			S += i.capitalize() + ' '
		return S


class Solution:

	def transform(self, s):
		result = ''
		temp = ''
		for i in s:
			if i == ' ':
				result += temp.capitalize()
				result += ' '
				temp = ''
			else:
				temp += i
		result += temp.capitalize()
		return result


class Solution:

	def transform(self, str):
		str = str.title()
		return str


class Solution:

	def transform(self, s):
		a = s.split()
		ans = []
		for i in range(len(a)):
			b = a[i].capitalize()
			ans.append(b)
		return ' '.join(ans)


class Solution:

	def transform(self, s):
		result = ''
		found = False
		for i in range(len(s)):
			if i != 0:
				if s[i] == ' ':
					result = result + s[i]
					result = result + s[i + 1].capitalize()
					found = True
				else:
					if i != 0:
						if found == True:
							found = False
							continue
					result = result + s[i]
			else:
				if i == 0:
					result = result + s[i].capitalize()
					continue
				if i != 0:
					if found == True:
						found = False
						continue
				result = result + s[i]
		return result


class Solution:

	def transform(self, s):
		words = s.split()
		output_string = ''
		for i in words:
			output_string = output_string + i.capitalize() + ' '
		return output_string


class Solution:

	def transform(self, s):
		temp = ''
		temp += s[0].upper()
		n = len(s)
		for i in range(1, n):
			if s[i] != ' ' and s[i - 1] == ' ':
				temp += s[i].upper()
			else:
				temp += s[i]
		return temp


class Solution:

	def transform(self, s):
		r = s.split()
		p = ''
		for i in r:
			p += i.capitalize() + ' '
		return p


class Solution:

	def transform(self, s):
		s_list = s.split(' ')
		n_list = []
		for w in s_list:
			n = w[0].upper() + w[1:]
			n_list.append(n)
		return ' '.join(n_list)