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 ?
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
Post a Comment