Python list is a collection of arbitrary objects, ordered, dynamic, mutable, somewhat similar to an array in other programming languages but more flexible. The list has many attributes and methods that we can use.
- Python lists are dynamic.
- Lists in Python are mutable.
- Lists are ordered.
- Lists can be nested to arbitrary depth.
- Lists can contain any arbitrary objects.
- List elements can be accessed by index.
To find the length of the list, use the len() method.
list = [11, 18, 19, 21, 46, 29] print(len(list))Output
6To calculate the total occurrence of a given List element, use the count() method.
list = [11, 18, 19, 21, 46, 29, 19] print(list.count(19))Output
2To calculate the minimum of all the list elements, use the min() function.
list = [11, 18, 19, 21, 46, 29, 19] print(min(list))Output
11To calculate the maximum of all the list elements, use the max() function.
list = [11, 18, 19, 21, 46, 29, 19] print(max(list))Output
46Python list methods
list.append()
To append or add a list in Python, use the append() method.
listA = ['PS5', 'XboxSeriesX'] listA.append('Nintendo Switch') print(listA)Output
['PS5', 'XboxSeriesX', 'Nintendo Switch']list.extend()
To add the content of one list to another list, use the extend() method.
Output
['PS5', 'XboxSeriesX', 'Returnal', 'Halo Infinite']list.pop()
To remove an element from the list, use the pop() method.
list = [11, 18, 19, 21, 46, 29, 19] print(list.pop())Output
19That is it for Python list attributes.
2021/06/05 — Edit:
I wrote this article last year, and since have learned more about how python works internally. The solution below indeed works, but is rather inefficient.
The getattr, setattr, hasattr, functions are great and have a time and place to be used, but they require a lookup of that object before accessing/checking for an attribute.
You can add other attribute names to the Area, Height, Length, and Width lists on the Attributes tab. Once added, the attributes populate with the area, height, length, and width values for features, as appropriate. For example, if you add the ARA_ attribute to the Area list on the Attributes tab, it can populate using the
Buildings tool. Below is a list of the different tools that calculate attribute values and the types of attributes they populate. When you add fields to the lists on the Attributes tab, those attributes can be used in addition to the default values in each list. Buildings X X X X Calculate Height X Calc Metrics X X X The Property Configuration dialog box appears.Tool nameAngleAreaHeightLengthWidth
A text box appears in the list.