How do we convert a string to a set in Python?

PythonServer Side ProgrammingProgramming

Python’s standard library contains built-in function set() which converts an iterable to set. A set object doesn’t contain repeated items. So, if a string contains any character more than once, that character appears only once in the set object. Again, the characters may not appear in the same sequence as in the string as set() function has its own hashing mechanism

>>> set("hello")
{'l', 'h', 'o', 'e'}


raja
Published on 08-Feb-2018 18:55:20
Advertisements