首页 > 技术文章 > 【KataDaily 191015】Sort the Gift Code

bcaixl 2019-10-15 09:17 原文

题目:

Happy Holidays fellow Code Warriors!

Santa's senior gift organizer Elf developed a way to represent up to 26 gifts by assigning a unique alphabetical character to each gift. After each gift was assigned a character, the gift organizer Elf then joined the characters to form the gift ordering code.

Santa asked his organizer to order the characters in alphabetical order, but the Elf fell asleep from consuming too much hot chocolate and candy canes! Can you help him out?

Sort the Gift Code

Write a function called sortGiftCode/sort_gift_code/SortGiftCode that accepts a string containing up to 26 unique alphabetical characters, and returns a string containing the same characters in alphabetical order.

Examples:

sort_gift_code( 'abcdef' ) # 'abcdef' sort_gift_code( 'pqksuvy' ) # 'kpqsuvy' sort_gift_code( 'zyxwvutsrqponmlkjihgfedcba' ) # 'abcdefghijklmnopqrstuvwxyz'

 

解题方法:

def sort_gift_code(code):
    return "".join(sorted(code))

 

推荐阅读