Answer to Question #196968 in Python for kavya

Question #196968

print the combinations of words in lexicogarphical order which are not adjacent in the given input sentence


1
Expert's answer
2021-05-23T08:49:44-0400
#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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS