Sort the words
Problem to sort words by s1 alphabetical order.
input: s1="k" s2="welcome to mycrazycoding family" if s1='k', the alphabetical order start with 'k' so k,l,m,n,....z,a,b,c,d,e,...j. The final output is "mycrazycoding to welcome family".
Example-1:
Input : s1 = "k" s2 = "welcome to mycrazycoding family" Output : mycrazycoding to welcome family
Example-2:
Input : s1 = "j" s2 = "stop worrying and start living" Output : living stop start worrying and
Solution
s1 = "k" s2 = "welcome to mycrazycoding family" s3 = s2.split() a = ord(s1) b = ord("z") c = ord("a") d = "" k = "" for i in range(a,b+1): d += chr(i) for j in range(c,a): d += chr(j) for x in d: for y in s3: if(x==y[0]): k += y k += " " print(k.strip())
Output
mycrazycoding to welcome family