In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to analyze the ordered and variable data set List in python, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
A list is an ordered and variable collection of data. the so-called ordering means that the data in the list will be stored in the order in which it is stored. The so-called variable means that the length of the list will grow with the increase of data, not a fixed size.
What is the use of lists as the most commonly used basic data structure? For example, if we want to dynamically access provinces, municipalities and autonomous regions across the country, we can use lists. Let's deposit a few provinces first:
Open IDLE first
Then enter
Provinces = ['Zhejiang', 'Jiangsu', 'Shanghai']
Create a new list called provinces with initial values of 'Zhejiang', 'Jiangsu' and 'Shanghai'. The list contains a total of three elements. Typing provinces directly into IDLE will display the contents of the list.
Len (provinces) can see how many elements there are in the list
What if we have to add other provinces?
You can use the append () method that comes with the list:
Provinces.append ('Guangdong Province')
Guangdong Province is automatically added to the end of the list, indicating that the list is orderly and will be arranged in the order in which the list data is added.
If you want to delete a specified element, you can use remove ()
Provinces.remove ('Shanghai')
If you want to delete data from a particular index, you can use the pop () function, and so on, what is an index? The so-called index is the position of the data in the list, and the index is counted from 0.
We delete the data with index 1
Jiangsu has been deleted, careful students may have found that when pop (1), the deleted value 'Jiangsu' is displayed, this is because the pop () method will return the deleted data at the same time, which literally pops up the data.
What if pop () doesn't write the index value?
Yes, if you don't write the index value, the last element will pop up.
Now there is only one element of Zhejiang left in the list. The data is urgent. Let's add some data first. We can use the append () method. That's a good idea, but we also have other quick methods:
The extend () method adds a new list to the end of the original list.
What if we want to add elements to the specified location?
Insert (1Jing 'Jiangsu') inserts the 'Jiangsu' element in the first index position, and the 'Guangdong' in the original No. 1 index position and all subsequent elements are moved back one place.
What if we insert another 'Jiangsu'? Does the list allow duplicate data?
Well, the list used to allow duplicate data, so is there a data structure that does not allow duplicate data?
After reading the above, have you mastered the method of analyzing the ordered and variable data set List in python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.