Basic operation list of Python3 list, tuple, dictionary, set

Overview

It's easy to forget about the basic operations of Python lists, tuples, dictionaries, and sets. Behavior in Python 3.x series.

is mutable?

list Tuple dictionary set
Yes No Yes Yes

Basic operation quick reference table

operation list Tuple dictionary set
Generate empty collection list()
[ ]
tuple()
( )
dict()
{ }
set()
literal [0, 1] (0, 1) {'A': 0, 'B': 1} {0, 1}
Duplicate(Shallow copy) list(a)
a.copy()
a[:]
tuple(a)
Substitution
dict(a)
a.copy()
set(a)
a.copy()
add to a.append(val) - a[key] = val a.add(val)
Join(in-place) a.extend(b)
a += b
- a.update(b) a.update(b)
a |= b
Join(not-in-place) a + b a + b - a | b
a.union(b)
Join(starred expression[^starred]) [*a, *b] (*a, *b)
*a, *b
{**a, **b} {*a, *b}
Insert(Single element) a.insert(idx, val)
a[idx:idx] = val,
- - -
Insert(Multiple elements) a[idx:idx] = b - - -
Intersection - - - a & b
a.intersection(b)
Difference - - - a - b
a.difference(b)
Delete(Value specification) a.remove(val) - - a.remove(val)
Delete(Key specification) del a[idx]
del a[start:stop:step]
- del a[key] -
Delete all a.clear()
del a[:]
- a.clear() a.clear()
Element count len(a)
a.count()
len(a) len(a) len(a)

[^ starred]: Available from Python 3.5.

Recommended Posts

Basic operation list of Python3 list, tuple, dictionary, set
Basic grammar of Python3 series (list, tuple)
Basic grammar of Python3 system (dictionary)
Python basic operation 1st: List comprehension notation
Python> empty XXX (XXX: dict, list, tuple, set)> {} / [] / () / set ()
List of python modules
Python Basic Course (7 Dictionary)
Basic operation of pandas
Basic operation of Pandas
Python3 List / dictionary memo
Basic knowledge of Python
Basic operation of Python Pandas Series and Dataframe (1)
Summary of Python sort (list, dictionary type, Series, DataFrame)
How to write a list / dictionary type of Python3
Python list, for statement, dictionary
Summary of Python3 list operations
To speed up python, summarize the amount of calculation of collection type (list / tuple / dictionary / set) for each purpose.
Operation of filter (None, list)
Python Basic Course (5 List Tuples)
[Python] Copy of multidimensional list
Basic usage of Python f-string
[Note] List of basic commands for building python / conda environment
[Scientific / technical calculation by Python] Basic operation of arrays, numpy
Summary of Hash (Dictionary) operation support for Ruby and Python
Python: Create a dictionary from a list of keys and values
[Python] List of major destructive methods of list operation (addition / deletion / sorting)
Learning record (6th day) #Set type #Dictionary type #Mutual conversion of list tuple set #ndarray type #Pandas (DataFrame type)
[Python] How to create a table from list (basic operation of table creation / change of matrix name)
[Python] Tuple version of prefecture pull-down
[Python] Operation memo of pandas DataFrame
Expansion by argument of python dictionary
Basic Python operation 2nd: Function (argument)
About the basics list of Python basics
Basic study of OpenCV with Python
Study from Python Hour6: Frequently used data types: tuple type, set type, dictionary type
Display a list of alphabets in Python 3
[Introduction to Udemy Python3 + Application] 17. List operation
Python basic operation 3rd: Object-oriented and class
python> Convert tuple to list> aList = list (pi_tuple)
[python] Get a list of instance variables
Basic grammar of Python3 system (character string)
[Python Iroha] Difference between List and Tuple
Summary of built-in methods in Python list
[Python] list
Python dictionary
Python Basic Course (at the end of 15)
Summary of how to use Python list
Set the process name of the Python program
[Python] dictionary
Basic grammar of Python3 system (included notation)
[Python] Get a list of folders only
Python dictionary
Extract elements (using a list of indexes) in a NumPy style from a Python list / tuple
Python> zip (* list4)> Matrix conversion> List and tuple argument expansion / dictionary argument expansion / local variable dictionary locals ()
[Python / DynamoDB / boto3] List of operations I tried
[python] Check the elements of the list all, any
Correspondence summary of array operation of ruby and python
[Python] Sort the list of pathlib.Path in natural sort
Automatic operation of Chrome with Python + Selenium + pandas
Unattended operation of Google Spreadsheets (etc.) in Python
[python] Create a list of various character types