Python> set> Convert with set ()> dictionary is only key> I was taught how to convert the values of dictionary to set / dir ({}) / help ({}) / help ({} .values)

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

Matters taught

@ shiracamus's Comment taught me how to retrieve dictionary values.

I also learned about the following.

Thank you for the information.

Recommended Posts

Python> set> Convert with set ()> dictionary is only key> I was taught how to convert the values of dictionary to set / dir ({}) / help ({}) / help ({} .values)
The 15th offline real-time I tried to solve the problem of how to write with python
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
[python] How to check if the Key exists in the dictionary
How to convert an array to a dictionary with Python [Application]
The story that the private key is set to 600 with chmod
How to write offline real time I tried to solve the problem of F02 with Python
I want to output the beginning of the next month with Python
How to check the memory size of a dictionary in Python
Python> Comprehension> cells> I was taught how to use double comprehension / itertools
I tried to improve the efficiency of daily work with Python
I was surprised at how to save objects with python, which is lean and very energy-saving.
The 16th offline real-time how to write problem was solved with Python
[Python] What is a formal argument? How to set the initial value
How to crop the lower right part of the image with Python OpenCV
[Introduction to Python] How to sort the contents of a list efficiently with list sort
I want to batch convert the result of "string" .split () in Python
I tried to get the authentication code of Qiita API with Python.
[Python] How to set the (client) window size inside the browser with Selenium
The 15th offline real-time how to write problem was solved with python
I tried to get the movie information of TMDb API with Python
[Introduction to Python] What is the method of repeating with the continue statement?
[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
Note: How to get the last day of the month with python (added the first day of the month)
[Python Tips] How to retrieve multiple keys with the maximum value from the dictionary
How to get a list of files in the same directory with python
I tried to automatically send the literature of the new coronavirus to LINE with Python
[Introduction to Python] How to get the index of data with a for statement
Convert Windows epoch values to date with python
How to specify attributes with Mock of python
How to get dictionary type elements of Python 2.7
This is the only basic review of Python ~ 3 ~
Convert the character code of the file with Python3
linux / c> link> Get the execution result of the shell command in the C program> I was taught how to use popen ()
I tried to find out how to streamline the work flow with Excel x Python ④
Get the value of a specific key in a list from the dictionary type in the list with Python
How to store Python function in Value of dictionary (dict) and call function according to Key
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to put out the frequent word ranking of LINE talk with Python
I tried to automate the article update of Livedoor blog with Python and selenium.
The theory that the key to controlling infection with the new coronavirus is hyperdispersion of susceptibility
I tried to find out how to streamline the work flow with Excel x Python ①
Here is one of the apps with "artificial intelligence" that I was interested in.
How to check in Python if one of the elements of a list is in another list
How to count the number of occurrences of each element in the list in Python with weight
How to set the development environment for each project with VSCode + Python extension + Miniconda
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to compare the processing speed with dplyr of R and pandas of Python
I thought about why Python self is necessary with the feeling of a Python interpreter
[Python] How to remove duplicate values from the list
How to convert / restore a string with [] in python
How to add help to HDA (with Python script bonus)
How to get the number of digits in Python
I tried to summarize how to use matplotlib of python
I tried to touch the CSV file with Python
How to convert a class object to a dictionary with SQLAlchemy
I tried to solve the soma cube with python
[Python] How to specify the download location with youtube-dl
Convert the image in .zip to PDF with Python