나는 이렇게 학습한다/Algorithm & SQL

0209. Sort the Gift Code

daco2020 2023. 2. 9. 22:12
반응형

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 (Input -- => Output):

"abcdef"                      -- => "abcdef"
"pqksuvy"                     -- => "kpqsuvy"
"zyxwvutsrqponmlkjihgfedcba"  -- => "abcdefghijklmnopqrstuvwxyz"



Solution:

sort_gift_code = lambda code: ''.join(sorted(code))


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0211. Remove duplicates from list  (0) 2023.02.12
0210. Is it a number?  (0) 2023.02.10
0209. Sort Out The Men From Boys  (0) 2023.02.09
0207. Divide and Conquer  (0) 2023.02.08
0206. Find the nth Digit of a Number  (0) 2023.02.07