Given a string s
return an organized string in alphabetical order. Capital letters should be returned first. Number digits should be at the end of the returned string, and should be returned in numerical order. Ignore any special characters.
def sort(s):
from string import ascii_lowercase, ascii_uppercase
alphabet = list(ascii_uppercase) + list(ascii_lowercase) + list("0123456789")
out = ""
for letter in alphabet:
for char in s:
if char == letter:
out += char
return out
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Tests")
def test_group():
@test.it("dcba")
def test_case0():
test.assert_equals(sort("dcba"), "abcd")
@test.it("LNabcdMOP")
def test_case1():
test.assert_equals(sort("LNabcdMOP"), "LMNOPabcd")
@test.it("AD2A3S4KB6k781bjasf")
def test_case2():
test.assert_equals(sort("AD2A3S4KB6k781bjasf"), "AABDKSabfjks1234678")
@test.it("KJBOkjASFIBUaf6")
def test_case3():
test.assert_equals(sort("KJBOkjASFIBUaf6"), "ABBFIJKOSUafjk6")
@test.it("KJs&g54%3do12bLS@8765AD$Flj")
def test_case4():
test.assert_equals(sort("KJs&g54%3d99o512bLS@85AD$Flj"), "ADFJKLSbdgjlos1234555899")
@test.it("kb1342sADS6!#%*(&#%!234Fgb;*&^!#%lbj8K4(&!@5A*BFDSK9756LB")
def test_case5():
test.assert_equals(sort("kb1342sADS6!#%*(&#%!234Fgb;*&^!#%lbj8K4(&!@5A*BFDSK9756LB"), "AABBDDFFKKLSSbbbgjkls122334445566789")