1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Set variable output is randomizing [duplicate]

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024 às 13:12.

  1. Stack

    Stack Membro Participativo

    I have created one Set variable and while printing the variables the elements order are randomized/ jumbled. But this is working fine in list. Do we have any specific reason

    # List:
    sqr_pos_int = [i**2 for i in range(1,11)]
    print(sqr_pos_int)

    # Output:
    # [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

    # Set:
    set_sqr_post_int = set(sqr_pos_int)
    print(set_sqr_post_int)

    # Output:
    # {64, 1, 4, 36, 100, 9, 16, 49, 81, 25}

    # Hardcore Set variable:
    set_dummy = {1,4,9,16,25,36,49,64,81,100}
    print(set_dummy)

    # Output:
    # {64, 1, 4, 36, 100, 9, 16, 49, 81, 25}


    I am running the syntax in VSCode as *ipynb format and expecting the result as below.

    {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}


    Thanks in advance.

    Continue reading...

Compartilhe esta Página