PRACTICE WITH STRINGS ===================== # WAP TO REVERSE ORDER OF WORDS. HINT: input : "Python is Object Oriented" output : "Oriented Object is Python" Explanation: ============= input = string string ==> list (l) ==> split() l1 = [] we need to append all the list elements (l data) into l1 in reverse l1 ==> string ==> join() ============================================ # WAP TO REVERSE ORDER OF WORDS. strData = input("Enter a string:") listData = strData.split(' ') # print(listData) # print(type(listData)) appendedList = [] # empty list # index = len(listData) - 1 # # while index >= 0: # appendedList.append(listData[index]) # index = index - 1 for i in listData[::-1]: appendedList.append(i) # print(appendedList) resString = ' '.join(appendedList) print(resString) ==================================================== # WAP REVERSE THE INTERNAL CONTENT OF EACH WORD IN A GIVEN STRING. """ Hint: input = "Python is Easy Programming Langauge" output = "nohtyP si ysaE gnimmargorP eguagnaL" Explanation: 1) take string as an input. 2) string ==> list ===> split() 3) empty list 4) traversing on converted list in forward direction while traversing, we should reverse each element of the list and append that reverse element into new list 5) appended list ==> string ==> join() """ ===================================== strData = input("Enter a string:") listData = strData.split() newList = [] for i in listData: reverseElement = i[::-1] newList.append(reverseElement) resString = ' '.join(newList) print(resString) ============================================ # WAP TO PRINT CHARACTERS AT ODD POSITIONS AND EVEN POSITIONS FOR THE GIVEN STRING """ Hint: input ==> "Python" Output: 1, 3, 5 ==> odd positions 0, 2, 4 ==> even positions """ # using slicing strData = input("Enter a string data:") print("The Characters at Odd Positions are:",strData[1::2]) print("The Characters at Even Positions are:",strData[0::2]) # using loop # the characters of even positions of the string: print("The Characters at Even Positions are:") index = 0 while index < len(strData): print(strData[index],end = ',') index += 2 print() print("The Characters at Odd Positions are:") # the characters at odd positions: index = 1 while index < len(strData): print(strData[index],end = ',') index = index + 2 ======================================================= # WAP TO SORT THE CHARACTERS OF THE STRING AND FIRST ALPHABET SYMBOLS FOLLOWED BY NUMERIC VALUES. """ input: 9B7R1A8S output: ABRS1789 """ s = input("Enter some String data:") s1 = s2 = output = "" for i in s: if i.isalpha(): s1 = s1 + i else: s2 = s2 + i for j in sorted(s1): output = output + j for k in sorted(s2): output = output + k print(output)