물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Srot the inner ctonnet in dsnnieedcg oredr

BEstyle 2022. 11. 1. 13:55

DESCRIPTION:

You have to sort the inner content of every word of a string in descending order.

The inner content is the content of a word without first and the last char.

Some examples:

"sort the inner content in descending order"  -->  "srot the inner ctonnet in dsnnieedcg oredr"
"wait for me"        -->  "wiat for me"
"this kata is easy"  -->  "tihs ktaa is esay"

Words are made up of lowercase letters.

The string will never be null and will never be empty. In C/C++ the string is always nul-terminated.

Have fun coding it and please don't forget to vote and rank this kata! :-)

I have also created other katas. Take a look if you enjoyed this kata!


def sort_the_inner_content(words):
    alist=words.split(" ")
    print(alist)
    for i in range(len(alist)):
        if len(alist[i])>=4:
            alist[i]=alist[i][0]+''.join(sorted(alist[i][1:len(alist[i])-1]))[::-1]+alist[i][-1]
    return " ".join(alist)

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Coding Meetup #8 Will all continents be represented?  (0) 2022.11.02
N-th Fibonacci  (0) 2022.11.02
String array dupliciates  (0) 2022.11.01
Difference of 2  (0) 2022.11.01
Steps in Primes  (0) 2022.11.01