Introduction
Kata – https://www.codewars.com/kata/string-reordering/train/python
Instructions
The input will be an array of dictionaries.
Return the values as a string-seperated sentence in the order of their keys’ integer equivalent (increasing order).
The keys are not reoccurring and their range is -999 < key < 999. The dictionaries’ keys & values will always be strings and will always not be empty.
Example
Input: List = [ {'4': 'dog' }, {'2': 'took'}, {'3': 'his'}, {'-2': 'Vatsan'}, {'5': 'for'}, {'6': 'a'}, {'12': 'spin'} ] Output: 'Vatsan took his dog for a spin'
My Solution
def sentence(List): return ' '.join([list(a.items())[0][1] for a in sorted(List, key=lambda k: int(list(k.items())[0][0]))])