Skip to content

Latest commit

 

History

History
55 lines (32 loc) · 853 Bytes

Ordering_the_words.md

File metadata and controls

55 lines (32 loc) · 853 Bytes

CodeWars Python Solutions


Ordering the words!

Given a string, you need to write a method that order every letter in this string in ascending order.

Also, you should validate that the given string is not empty or null. If so, the method should return:

"Invalid String!"

Notes

  • the given string can be lowercase and uppercase.
  • the string could include spaces or other special characters like '# ! or ,'

Examples

"hello world" => " dehllloorw"
"bobby"       => "bbboy"
""            => "Invalid String!"
"!Hi You!"    => " !!HYiou"

Given Code

def order_word(s):
    pass

Solution

def order_word(s):
    return "".join(sorted([c for c in s])) if s else "Invalid String!"

See on CodeWars.com