You could remove the call to sorted() here actually, it will still work.