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.

classification
Title: set() bug
Type: behavior Stage:
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ammar2, rhettinger, styg
Priority: normal Keywords:

Created on 2016-12-31 17:33 by styg, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg284402 - (view) Author: styg (styg) Date: 2016-12-31 17:33
set() method leads to this error:
a=[1,2,3,3]
b=set(a)
print b
>> set([1,2,3]) # should be [1,2,3]
msg284403 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2016-12-31 17:41
Why would the expected output be [1, 2, 3]? That is the list notation for having a list that contains the elements 1, 2 and 3.
msg284407 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-12-31 18:48
Sorry Styg, but this is the expected behavior.

To achieve what you wanted, write this is instead:

   print list(set(a))
History
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73308
2016-12-31 18:48:09rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg284407

resolution: not a bug
2016-12-31 17:41:10ammar2setnosy: + ammar2
messages: + msg284403
2016-12-31 17:33:48stygcreate