Get Python list elements with multiple indexes (number) Simple method

When extracting multiple lists from a Python list, if they are continuous, they can be easily extracted by slicing, but I couldn't find a method for random cases, so I will write an article.

environment

Python 3.7.3

Specified by tuple

list = ['banana', 'apple', 'lemon', 'grape', 'kiwi']
[list[i] for i in (1,4)]  #['apple', 'kiwi']

Or specify in the list

list = ['banana', 'apple', 'lemon', 'grape', 'kiwi']
list2=[2,3]
[list[i] for i in list2] #['lemon', 'grape']

There was an article that used modules such as Numpy, but I was able to write it simply!

I referred to this English site

Recommended Posts

Get Python list elements with multiple indexes (number) Simple method
Specify multiple list indexes (Python)
Get the number of specific elements in a python list
Delete multiple elements in python list
[Python] Display list elements with variadic arguments
A simple to-do list created with Python + Django
How to return multiple indexes with index method
Get date with python
Initialize list with python
Get corporate number at once via gbizinfo with python
Get the size (number of elements) of UnionFind in Python
Get country code with python
Get Twitter timeline with python
[Python] Calculation method with numpy
Get Youtube data with python
Simple sales tool creation with Python GUI: Employee number search
Get a list of purchased DMM eBooks with Python + Selenium
ABC161D Lunlun Number with python3
Get thread ID with python
Get started with Python! ~ ② Grammar ~
Get stock price with Python
Getting list elements in Python
Get home directory with python
Get keyboard events with python
Get Alembic information with Python
How to delete multiple specified positions (indexes) in a Python list
Get a list of files in a folder with python without a path
[Python] Get elements by specifying attributes with prefix search in BeautifulSoup
Extract multiple list duplicates in Python
Number recognition in images with Python
Get started with Python! ~ ① Environment construction ~
Link to get started with python
Get reviews with python googlemap api
random French number generator with python
Get web screen capture with python
Get the weather with Python requests 2
[Python] Get economic data with DataReader
Convert list to DataFrame with python
How to get started with Python
Post multiple Twitter images with python
[Small story] Get timestamp with Python
Animate multiple still images with Python
Get Qiita trends with Python scraping
Get Redmine User list with DataFrame
Extract multiple elements with Numpy array
Automate simple tasks with Python Part0
Multiple integrals with Python and Sympy
[Python] Creating multiple windows with Tkinter
Get started with Python in Blender
Get weather information with Python & scraping
Get the number of searches with a regular expression. SeleniumBasic VBA Python
Get a list of packages installed in your current environment with python
[Python] How to use list 2 Reference of list value, number of elements, maximum value, minimum value
Get the number of articles accessed and likes with Qiita API + Python
Get additional data in LDAP with python
Get property information by scraping with python
Creating a simple PowerPoint file with Python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Simple Slack API client made with Python
Automatic update method with python Pyinstaller exe