Answer to Question #280449 in Python for adhichinna

Question #280449

New Dictionary


Peter is making a new dictionary. He wants to arrange the words in the ascending order of their length and later arrange the ones with the same length in lexicographic order. Each word is given a serial number according to its position. Find the word according to the serial number.


The serial number of words in Peter's dictionary is as follows


Word


Serial Number


A


B


1.


C


24


25


26


27


AA


AB


28


BA


1
Expert's answer
2021-12-20T08:35:02-0500
def sortLexo(word):
    # Split the my_string
    words = word.split()
    words.sort()

    # in alphabetical manner.
    for i in words:
        print(i)


if __name__ == '__main__':
    word = "A B  C 24 25 26 27 AA AB 28 BA"
    # function
    sortLexo(word)

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