def mysplit(strng):

a="" b=[] count=0 for i in strng: if i==' ': if a!='': b.append(a) a="" else: a+=i #if count==len(strng)-1: # a+=i # b.append(a) #count+=1 if a!='': b.append(a) return b print(mysplit("To be or not to be, that is the question ")) print(mysplit("To be or not to be,that is the question ")) print(mysplit(" ")) print(mysplit(" abc ")) print(mysplit(""))

OUTPUT:
['To', 'be',' or', 'not', 'to', 'be,', 'that', 'is', 'the', 'question']
['To', 'be',' or', 'not', 'to', 'be, that', 'is', 'the', 'question']
[ ]
['abc']
[ ]

Comments

Popular posts from this blog