python - set properties and union method -


i have question regarding set. have following code illustrate question.

def f2( s ):     return { c.upper() c in s if c.isalpha() }  print f2( "a r'a|cccc^#zz" ) print f2( "a r'a|cccc^#zz" ).union( [( 'b', )] ) print f2( "a r'a|cccc^#zz" ).union( [( 't', )]) 

the result is:

set(['a', 'c', 'r', 'z']) set(['a', ('b',), 'c', 'r', 'z']) set(['a', 'c', 'r', 'z', ('t',)]) 

why set order in order ? in first time can guess ordered according a-z (hash function?) why there difference in position of tuple in other lines ?

sets have no order.

from documentation:

the sets module provides classes constructing , manipulating unordered collections of unique elements. common uses include membership testing, removing duplicates sequence, , computing standard math operations on sets such intersection, union, difference, , symmetric difference.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -