python memo: Treat lists as a set type

Self-introduction

It's my first article. --Name: HotAllure --Origin: Mechanical Engineering (Master) --Hobbies: Detective stories, handicrafts, coffee ――Job content 1: Get on the trend of new information technology and try various footwork lightly ――Job content 2: Acquire deep learning and devise new services

I was assigned to an information-related workplace in Bali Bali, but as mentioned above, my major in university was mechanical, and the opportunity to come into contact with programming was that I did C in class or touched Arduino at a laboratory workshop. , I used Matlab to do the statistical processing necessary for my research, and so on.

After joining the company, I started working with python, which is used by the majority of people mainly for deep learning, and touched Tensorflow to modify the tutorial model. ... but it's not a sweet world (at least for me) that I can suddenly master deep learning, coupled with anxious personality if I don't work on the application after securing the basics.

I've already been very much indebted to Qiita's wonderful articles, but I'm embarrassed to expose my immature self, and I'm stuck studying lonely, and while I'm depressed, I'm studying Qiita I saw a person using it as a memorandum, and I thought it was true.

First of all, I'm using python, and I'm going to use it as a memorandum of where I got stuck and how to solve it. I hope I can write other articles if I can afford it.

Note: Extract common elements from the list

I referred to the article by yamao2253, the third pattern. http://qiita.com/yamao2253/items/309fdaa74b8f9d38ac46 The rest is here. http://www.sejuku.net/blog/21923

Was there a variable type such as python or set type? Mumumu.

and_set.py


set1 = set(['a','b','c','d'])
set2 = set(['c','d','e','f'])

#Get the intersection of set1 and set2
and_set = set1.intersection(set2)

print(and_set) #set(['c','d'])

#When returning set to list
and_list=list(and_set)
print(and_list) #['c','d']

The methods intersection and the & operator seem to work in the same way.

About other set operations

https://docs.python.jp/3/tutorial/datastructures.html

set_method.py


#Difference set
dif_set = set1.difference(set2)              #(set['a','b'])
#Union
uni_set = set1.union(set2)                   #(set['a','b','c','d','e','f'])
#Symmetric difference set
symdif_set = set1.symmetric_difference(set2) #(set['a','b','e','f'])

There seem to be many other things.

Postscript

A python study article by __ zenbo __ in the first year of junior high school. http://qiita.com/zenbo/items/9ed2db6dc7180e6ea1ff

Great at a young age. I also want to apprentice.

Recommended Posts

python memo: Treat lists as a set type
(Python) Treat integer values as a set of flags
Python immutable type int memo
Python data type summary memo
[Python] Use JSON format data as a dictionary type object
Use pymol as a python library
Use blender as a python module
[Personal memo] Python sequence type / mapping type
[Python] Creating a scraping tool Memo
Treat Python in-class variables as private variables
Launch a Python script as a service
Install Python as a Framework with pyenv
Python memo
python memo
A Java programmer studied Python. (About type)
Python memo
A memo with Python2.7 and Python3 on CentOS
[Python memo] Be careful when creating a two-dimensional array (list of lists)
AtCoderBeginnerContest154 Participation memo (Python, A ~ E problem)
python memo
[Python] Sorting collection types as a reference
[python] [meta] Is the type of python a type?
[Python] Complete preprocessing Memo as it is
Python memo
Python as a strongly, dynamically typed language
Python memo
Python memo
[Python] I tried to get the type name as a string from the type function
A memo of a tutorial on running python on heroku
A memo that I wrote a quicksort in Python
A memo about writing merge sort in Python
Set up a test SMTP server in Python.
[Memo] I tried a pivot table in Python
Rewriting elements in a loop of lists (Python)
A memo when creating a python environment with miniconda
Set up a simple SMTP server in Python
Set up a Python development environment on Marvericks
A memo for creating a python environment by a beginner
Python set arithmetic
Python numeric type
python beginner memo (9.2-10)
python beginner memo (9.1)
Python set arithmetic
★ Memo ★ Python Iroha
[Python] EDA memo
Python 3 operator memo
[My memo] python
Python2 string type
Python3 metaclass memo
Python # string type
[Python] Basemap memo
Python beginner memo (2)
[Python] Numpy memo
A memo connected to HiveServer2 of EMR with python
How to set up a Python environment using pyenv
Specify a subcommand as a command line argument in Python
How to write a list / dictionary type of Python3
[Python] A memo to write CSV vertically with Pandas
A memo that I touched the Datastore with python
A memo about building a Django (Python) application with Docker
Python memo using perl-Dictionary type (case is not valid)