@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 1721 / 12833)
You can create a set from a list, string, tuple, or dictionary, discarding any duplicative values.
tried.
http://ideone.com/y39M6a
astring = set( 'letters' )
print(astring)
alist = set( [ 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5])
print(alist)
atuple = set( (3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5))
print(atuple)
adict = set( { 'item1': 'double edged sword', 'item2': 'Korejanai Robo'} )
print(adict)
result
Success time: 0 memory: 23304 signal:0
set(['s', 'r', 'e', 'l', 't'])
set([1, 2, 3, 4, 5, 6, 9])
set([1, 2, 3, 4, 5, 6, 9])
set(['item2', 'item1'])
The dictionary is only key.
@ No.1731 / 12833
When you give set() a dictionary, it uses only the keys:
@ shiracamus's Comment taught me how to retrieve dictionary values.
I also learned about the following.
dir({})
help({})
help({}.values)
Thank you for the information.
Recommended Posts