A python amateur tries to summarize the list ②

Introduction

Let's put together Python for super beginners https://qiita.com/kkhouse/items/675b846d0bcf41cd191f

Python beginners talk about how to remember this much https://qiita.com/kkhouse/items/74d7acb768e6542339ac

Python amateurs try to summarize the list ① https://qiita.com/kkhouse/items/a6cc69b81428701d12b2

It is a continuation of this area. I haven't made it into a series, but I have a feeling that it will be a series. We have set a limit on the amount of time we can spend, so this time we will rush to summarize the list.

Last time, I was grateful to hear that the method was called a method. I am grateful for your suggestions and will continue to do so.

Various methods

Since it's a big deal, I'll summarize it by giving various methods.

L.index(x,start,end)

In programming, there is the idea of index numbers. Simply put, it is the number attached to each element in the list. The first element is 0, and the numbers are added in order after that.

list = ["Kansai","Kanto","Tohoku"]

If there is a list, the index numbers are 0 for Kansai, 1 for Kanto, and 2 for Tohoku. Note that it starts from 0.

print(list[1])
#"Kanto"

You can call the corresponding element by entering the index number with [] in the variable containing the list.

Well the main subject. About the method L.index (x, start, end)

list = [1,2,3,4,5,6]
ind_list = list.index(3,1,5) 
print(ind_list)
#3

It's a bit complicated to write, but the element in () of the method () is called an argument, and in the above list, it is the first argument 3, the second argument 1, and the third argument 5. The index method then looks for the first argument between the second and third arguments. (Search for the numerical value 3 from index numbers 1 to 4) * Since the index of the last element is the number of elements -1, 5 in index (3.1,5) represents the 4th.

L.insert(x,i) The insert method adds the second argument to the location specified in the first argument.

list = [1,2,3,4,5,6]
print(list.insert(2,3.5)
#[1,2,3,3.5,4,5,6]

Note that it starts at 0

len function

Also, I often use the len function to get the number of elements in the list. len (list) gets the number of elements in list.

list = [1,2,3,4,5]
print(len(list))
#5

At the end

The list has an applied expression called comprehension. Since the if statement is involved, I will write it after summarizing the if statement.

See you tomorrow ~

Recommended Posts

A python amateur tries to summarize the list ②
Python amateurs try to summarize the list ①
How to get the last (last) value in a list in Python
Extract the value closest to a value from a Python list element
[Python] How to convert a 2D list to a 1D list
[Python] A program that rotates the contents of the list to the left
[Python] List Comprehension Various ways to create a list
How to clear tuples in a list (Python)
[Introduction to Python] What is the difference between a list and a tuple?
Make a copy of the list in Python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Python] Throw a message to the slack channel
[Python] Solution to the problem that elements are linked when copying a list
Python script to get a list of input examples for the AtCoder contest
How to get a list of files in the same directory with python
How to write a list / dictionary type of Python3
Things to note when initializing a list in Python
[Python] I want to make a nested list a tuple
[Python] How to output the list values in order
Python Note: The mystery of assigning a variable to a variable
I tried to summarize the string operations of Python
A road to intermediate Python
[Python] How to use list 1
Python list is not a list
[Introduction to Python] <list> [edit: 2020/02/22]
How to identify the element with the smallest number of characters in a Python list?
How to check in Python if one of the elements of a list is in another list
How to find the first element that matches your criteria in a Python list
[Python] I tried to summarize the array, dictionary generation method, loop method, list comprehension notation
Try to get the function list of Python> os package
[Python] How to make a list of character strings character by character
[python] Change the image file name to a serial number
[Python] It might be useful to list the data frames
How to shuffle a part of a Python list (at random.shuffle)
Change the standard output destination to a file in Python
Probably the easiest way to create a pdf with Python3
Write a python program to find the editing distance [python] [Levenshtein distance]
Get the number of specific elements in a python list
Developed a library to get Kindle collection list in Python
Build a Python environment and transfer data to the server
How to get a list of built-in exceptions in python
How to connect the contents of a list into a string
Get the value of a specific key up to the specified index in the dictionary list in Python
Recursively get the Excel list in a specific folder with python and write it to Excel.
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to write a Python class
Leave the troublesome processing to Python
[python] Manage functions in a list
In the python command python points to python3.8
Convert list to DataFrame with python
python / Make a dict from a list.
[Python] How to import the library
[Python] Make the function a lambda function
[Python] How to use list 3 Added
5 Ways to Create a Python Chatbot
About the basics list of Python basics
[Python] Change the alphabet to numbers
How to determine the existence of a selenium element in Python
[Introduction to Python] How to split a character string with the split function
A story that struggled to handle the Python package of PocketSphinx
I created a Python library to call the LINE WORKS API