snake comparator and list sorting