Ammar Askar <am...@ammaraskar.com> added the comment:

I think the key thing you're missing here is that the set() constructor can 
take any arbitrary iterable 
(https://docs.python.org/3/library/functions.html#func-set). It simply goes 
over all the elements inside and adds them all to the set. This is no different 
than the following for example:

    >>> for char in 'somestring': 
    ...   print(char)             
    ...                           
    s                             
    o                             
    m                             
    e                             
    s                             
    t                             
    r                             
    i                             
    n                             
    g                             
    >>>
    >>> for char in '':
    ...   print(char)
    ...
    >>>

When you iterate over a string, it simply goes over each character inside it.

> While set('somestring') gives me a set of size one

This should not be the case, set('something') should be giving you a set of 
size 9. Each element in the set being a character from the string 'somestring'

    >>> set('somestring')
    {'t', 's', 'e', 'n', 'g', 'o', 'r', 'i', 'm'}
    >>> len(set('somestring'))
    9

> set('') gives me an empty set (of size zero)

Now hopefully it should be obvious why this happens, the set() constructor goes 
over each character in the string. Which in this case, there aren't any because 
the string is completely empty. This leads to an empty set. This is no 
different than doing set([])

----------
nosy: +ammar2
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38327>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to