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 function for lists on numbers, sometimes sorts elements from smallest to largest, and sometimes not
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Piter, eric.smith, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2022-03-10 14:07 by Piter, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug_1.PNG Piter, 2022-03-10 14:07 Results
Messages (2)
msg414848 - (view) Author: PiTeR (Piter) Date: 2022-03-10 14:07
set function for lists on numbers, sometimes sorts elements from smallest to largest, and sometimes not
to find this bug, sometimes you need to display the result several times
example code:
def tupla():
    import random
    ilosc = random.randint(0,49)
    n=0
    lista=[]
    i=0
    while True:
        n = random.randint(1,100)
        lista.append(n)
        i=i+1
        if i==ilosc-1:
            break
    lista = set(lista)
    list(lista)
    print(lista)
msg414849 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-03-10 14:15
This is expected behavior. A set has no defined order. If you convert a set to a list, and you want some specific order, you'll need to sort it yourself.
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91130
2022-03-10 14:15:33eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg414849

resolution: not a bug
stage: resolved
2022-03-10 14:07:15Pitercreate