Added an extra function that works for lists and refactor getPrettyTextFromSet