Python Challenge: Sort String In Alphabetical Order And Remove Duplicates

preview_player
Показать описание

In this Daily Python Challenge, we will challenge you to create a script that will sort a Python string into alphabetical order while removing duplicates, whitespace and making all characters lower case.
Рекомендации по теме
Комментарии
Автор

These challenges are fun and I'm learning from your very pythonic solutions. On this one... the challenge implies that the returned string contains only alphabetic characters but the input string could contain ANY character. My solution took into account strings that might contain punctuation and digits. Not until I saw your solution did I consider a way of parsing such a string without an "if" statement to exclude punctuation and digits. I took another shot at it and, not including importing the "string" package or the line that gets the input string (input_s), two lines are needed:

(1) excluded_chars = string.punctuation + string.digits + ' '
(2) s = for ch in input_s if ch not in excluded_chars])))

It would be possible to do this in one line, but I wouldn't want to read it!

rickrawson
Автор

I am trying to do this without using sorted

notsure