python 字典,列表,元组
2015-05-25 15:55
253 查看
基础操作:
高级操作,实现栈:
高级操作,实现队列:
##########################列表############################# aList = [1,2,3,4,5] #python 中 list 是可变类型,像下面这样修改是合法的 #增 aList.append(6) #删 aList.pop() #改 aList[0] = 100 #查 print(aList[0]) for v in aList: print(v) ##############元组########################## aTuple = (1,2,3,4,5) #在python 元组是不可变类型,不可修改,像下面的操作时非法的 # aTuple[0] = 2 #查 for v in aTuple: print(v) ################字典######################### aDict = {"name":"zhengjinwei","age":23,"sex":"male"} #在python 中字典是可以修改的 #增 aDict["index"] = 1 #删 aDict.pop("index") aDict.clear() #改 aDict["name"]="bloodchilde" #查 for index,k in enumerate(aDict): print index,k,aDict[k]
高级操作,实现栈:
#python 中list 实现栈 class CStack: def __init__(self): self.__len = 0 self.__stack = [] def __del__(self): del self.__stack def push(self,obj): self.__stack.append(obj) self.__len += 1 def pop(self): if not self.__len: return None else: self.__len -= 1 return self.__stack.pop() def getStackLen(self): return self.__len def getStackData(self): return self.__stack stack = CStack() print(stack.getStackData()) print(stack.pop()) stack.push(1) stack.push("zjw") print(stack.getStackData()) print(stack.pop()) print(stack.pop())
高级操作,实现队列:
#python list 实现队列 class CQueue: def __init__(self): self.__queue = [] self.__len = 0 def __del__(self): del self.__queue def enter_queue(self,obj): self.__queue.append(obj) self.__len += 1 def del_queue(self): if not self.__len: return None else: self.__len -= 1 return self.__queue.pop(0) def view_queue(self): return self.__queue queue = CQueue() print(queue.view_queue()) # enter the queue queue.enter_queue(1) queue.enter_queue(2) print(queue.view_queue()) #out the queue print(queue.del_queue())#show 1 print(queue.del_queue())#show 2 print(queue.del_queue()) #will show None
相关文章推荐
- Python中元组,列表,字典的区别
- python 列表,元组,字典
- python列表,元组,字典
- python入门:基础,列表、元组、字典及集合类型
- python3基础: 元组tuple、 列表list、 字典dict、集合set。 迭代器、生成器
- Python笔记——基本数据结构:列表、元组及字典
- [Python]字典Dictionary、列表List、元组Tuple差异化理解
- Python 入门学习 -----变量及基础类型(元组,列表,字典,集合)
- python中列表,元组,字典知识点整理
- python之list列表、字典、元组、切片
- python-列表、字典、元组的员工信息处理接口(第二篇(五):基于列表、字典和元组的员工信息处理接口)
- Python列表、元组、集合、字典的区别和相互转换
- Python常用的内置序列结构(列表、元组、字典)学习笔记
- python 字符串/元组/列表/字典互转
- Python 入门学习 -----变量及基础类型(元组,列表,字典,集合)
- Python中列表/元组/集合/字典的理解
- python 列表list 元组tuple 字典dict 集合set 介绍
- Python学习整理之 列表list 元组tuple 字典dictionary
- python3判断字典、列表、元组为空以及字典是否存在某个key的方法
- Python 元组、列表、字典、字符串的操作