fork download
  1. import re
  2.  
  3. r = re.compile(r'\d+')
  4.  
  5. def sort_data(data):
  6. result_list = []
  7. data_list = data.split()
  8. keys = r.findall(data)
  9. for key, value in zip(keys, data_list):
  10. result_list.append((int(key), value))
  11. result_list.sort(key=lambda x: x[0])
  12. result_string = ' '.join(item[1] for item in result_list)
  13. return result_string
  14.  
  15.  
  16.  
  17. print(sort_data('4of Fo1r pe6ople g3ood th5e the2 7asd 8aaa 9fff 10sad'))
Success #stdin #stdout 0.02s 9744KB
stdin
Standard input is empty
stdout
Fo1r the2 g3ood 4of th5e pe6ople 7asd 8aaa 9fff 10sad