Python[四]:List and stack
来源:互联网 发布:linux打开终端 编辑:程序博客网 时间:2024/06/05 01:16
1.List和stack
- list.append(x)
- Add an item to the end of the list; equivalent to a[len(a):] = [x].
- list.extend(L)
- Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.
- list.insert(i, x)
- Insert an item at a given position. The first argument is the index of the element before which to insert, soa.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is equivalent to a.append(x).
- list.remove(x)
- Remove the first item from the list whose value is x. It is an error if there is no such item.
- list.pop([i])
- Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)
- list.index(x)
- Return the index in the list of the first item whose value is x. It is an error if there is no such item.
- list.count(x)
- Return the number of times x appears in the list.
- list.sort()
- Sort the items of the list, in place.
- list.reverse()
- Reverse the elements of the list, in place.
Using Lists as Stacks
The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (“last-in, first-out”). To add an item to the top of the stack, use append(). To retrieve an item from the top of the stack, use pop() without an explicit index.
- Python[四]:List and stack
- List, Queue and Stack
- Reverse linked list using stack and stack's implementation
- Python Dictionary and List
- Python list and tuple
- python list and tuple
- Stack ---- Implementation in C and Python
- [Python]Functions, Variables, and the Call Stack
- Python Books and resources list
- Python Container Tuple and List
- Python Container Dictionary And List
- [python] list.sort and sorted
- Python练习-- list and tuple
- python笔记-list and dict
- python isinstance(), stack,判断list, dict, tuple为空
- Trick (八)——list 模拟 stack(Python)
- 数据结构之“Ordered List and Sorted List”(四)
- python 系统学习笔记(四)--list
- Ogre 1.7版本重大改进
- 如何利用窗体身份验证创建 GenericPrincipal 对象
- (一)爬泰山,如人生 ---- 上山
- 【数论 / 数值】【RQNOJ】Hanoi双塔问题
- 关于MyGUI3.0+Ogre1.7
- Python[四]:List and stack
- Ogre 1.7 SDKTRAY 初探
- 正则表达式入门经典|学习笔记(一)
- Python[五]:Delete
- 阅读go语言源代码3
- Ogre 1.7的地形系统
- Python[六]:Tuples and Sequences
- Linux网络编程入门(转)
- Python[七]:Sets