print the combinations of words in lexicogarphical order which are not adjacent in the given input sentence
#lexological ordering lexicogarphical
InpString = "Sun rises in the east and sets in the west"
words = InpString.split()
AlternateWords_1=""
AlternateWords_2=""
r=0
for i in words:
if(r%2==0): AlternateWords_1=AlternateWords_1 + i + " "
if(r%2==1): AlternateWords_2=AlternateWords_2 + i + " "
r=r+1
print("Input String: %s",InpString)
print("Alternate Words Set-1: %s"%AlternateWords_1)
words = AlternateWords_1.split()
words.sort()
print("\nLexicogarphical Order: ")
for i in words:
print(i)
print("\nAlternate Words Set-2: %s"%AlternateWords_2)
words = AlternateWords_2.split()
words.sort()
print("Lexicogarphical Order: ")
for i in words:
print(i)
Comments
Leave a comment