34 lines
871 B
Python
34 lines
871 B
Python
# HumanEval/19
|
|
# Loki Mode Multi-Agent Solution
|
|
# Attempts: 1
|
|
# Passed: True
|
|
|
|
from typing import List
|
|
|
|
|
|
def sort_numbers(numbers: str) -> str:
|
|
""" Input is a space-delimited string of numberals from 'zero' to 'nine'.
|
|
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
|
|
Return the string with numbers sorted from smallest to largest
|
|
>>> sort_numbers('three one five')
|
|
'one three five'
|
|
"""
|
|
if not numbers or not numbers.strip():
|
|
return ''
|
|
|
|
word_to_num = {
|
|
'zero': 0,
|
|
'one': 1,
|
|
'two': 2,
|
|
'three': 3,
|
|
'four': 4,
|
|
'five': 5,
|
|
'six': 6,
|
|
'seven': 7,
|
|
'eight': 8,
|
|
'nine': 9
|
|
}
|
|
|
|
words = numbers.split()
|
|
sorted_words = sorted(words, key=lambda w: word_to_num[w])
|
|
return ' '.join(sorted_words) |