implement list trimming on the python server