This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ammar2
Recipients EmilBode, ammar2
Date 2019-09-30.15:27:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1569857257.49.0.00885401991896.issue38327@roundup.psfhosted.org>
In-reply-to
Content
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([])
History
Date User Action Args
2019-09-30 15:27:37ammar2setrecipients: + ammar2, EmilBode
2019-09-30 15:27:37ammar2setmessageid: <1569857257.49.0.00885401991896.issue38327@roundup.psfhosted.org>
2019-09-30 15:27:37ammar2linkissue38327 messages
2019-09-30 15:27:37ammar2create