LoginSignup
0
2

More than 5 years have passed since last update.

Python > set > set()にて変換 > dictionaryはkeyだけになる > dictionaryのvaluesをsetに変換する方法を教えていただきました / dir({}) / help({}) / help({}.values)

Last updated at Posted at 2017-03-15

@ 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.

試した。

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)
結果
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'])

dictionaryはkeyだけになる。

@ No.1731 / 12833

When you give set() a dictionary, it uses only the keys:

教えていただいた事項

@shiracamus さんのコメントにてdictionaryのvaluesを取り出す方法を教えていただきました。

以下についても教えていただきました。

  • dir({})
  • help({})
  • help({}.values)

情報感謝です。

0
2
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2