fork(3) download
  1. from itertools import accumulate, count
  2.  
  3. txt_file = ['3 love', '6 computers', '2 dogs', '4 cats', '1 I', '5 you']
  4. sorted_file = sorted(map(str.split, txt_file), key=lambda t: int(t[0]))
  5. output = []
  6. for i in accumulate(count(1)):
  7. if i > len(sorted_file):
  8. break
  9. output.append(sorted_file[i - 1][1])
  10. print(*output)
Success #stdin #stdout 0.03s 9836KB
stdin
Standard input is empty
stdout
I love computers