Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I found weird thing.
#1
I use python 3.7.0

if I type this,
a=set('12345')

and then type a,
outcome likes {3,1,2,4,5} or {4,1,2,3,5} or {1,3,4,2,5} in random sequence.

but I found this one.

if I type this
a=set(i for i in range (1,12) if i%2==0)
and then type a,
outcome is always {2,4,6,8,10} why ALWAYS outcome like this?

and one more weird thing,

when I type this
a=set(i for i in range (1,10) if i%2==0)
and then type a,
outcome is always {8,2,4,6} Whatttttttttttttttt

I think print of set-type is always random. is it wrong??
Reply
#2
You seem to have magically converted unicode characters to integers as well :-)

There is no ordering of sets, order (such as it is) is based on hash values. Ordering is not even an implementation detail in CPython (as it was for dictionaries in CPython 3.6 before becoming standard in 3.7).

Thus, there is no weirdness. The output order is whatever it happens to be and should not be relied on.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am confused with the key and value thing james1019 3 978 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  Need help i just started the whole thing gabriel789 16 3,233 Sep-12-2022, 08:04 PM
Last Post: snippsat
  i making a terminal sign up website thing Kenrichppython 1 1,713 Nov-04-2021, 03:57 AM
Last Post: bowlofred
  use thing before self sylvanas 3 2,351 Jul-21-2021, 04:54 PM
Last Post: sylvanas
  Not able to make a specific thing pause in pygame cooImanreebro 4 3,232 Dec-13-2020, 10:34 PM
Last Post: cooImanreebro
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,559 Nov-23-2020, 05:15 PM
Last Post: cananb
  Help with list thing please Yeyzon 1 2,061 Apr-19-2019, 07:51 AM
Last Post: snippsat
  Printing one thing from a list bidoofis 1 2,354 Feb-05-2019, 09:02 PM
Last Post: ichabod801
  Make one thing act like another Zman350x 2 2,212 Aug-16-2018, 06:45 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020