v26编程指南中文版数据结构

v26编程指南中文版数据结构

ID:30431663

大小:96.61 KB

页数:22页

时间:2018-12-29

v26编程指南中文版数据结构_第1页
v26编程指南中文版数据结构_第2页
v26编程指南中文版数据结构_第3页
v26编程指南中文版数据结构_第4页
v26编程指南中文版数据结构_第5页
资源描述:

《v26编程指南中文版数据结构》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、v26编程指南中文版数据结构Navigationindexmodules

2、next

3、previous

4、Pythonv2.6.5documentation?ThePythonTutorial?5.DataStructures数据结构?Thischapterdescribessomethingsyou'velearnedaboutalreadyinmoredetail,andaddssomenewthingsaswell.本章将更加详细的介绍一些你已经了解的东西,另外我们还会添加一些新的东西。5.1.MoreonListsList的更多细节?

5、Thelistdatatypehassomemoremethods.Hereareallofthemethodsoflistobjects:List数据类型还有其他的一些方法。如下是List的所有方法:list.append(x)Addanitemtotheendofthelist;equivalenttoa[len(a):]=[x].list.extend(L)Extendthelistbyappendingalltheitemsinthegivenlist;equivalenttoa[len(a):]=L.list.insert(i,

6、x)Insertanitematagivenposition.Thefirstargumentistheindexoftheelementbeforewhichtoinsert,soa.insert(0,x)insertsatthefrontofthelist,anda.insert(len(a),x)isequivalenttoa.append(x).list.remove(x)Removethefirstitemfromthelistwhosevalueisx.Itisanerrorifthereisnosuchitem.list.p

7、op([i])Removetheitematthegivenpositioninthelist,andreturnit.Ifnoindexisspecified,a.pop()removesandreturnsthelastiteminthelist.(Thesquarebracketsaroundtheiinthemethodsignaturedenotethattheparameterisoptional,notthatyoushouldtypesquarebracketsatthatposition.Youwillseethisno

8、tationfrequentlyinthePythonLibraryReference.)list.index(x)Returntheindexinthelistofthefirstitemwhosevalueisx.Itisanerrorifthereisnosuchitem.list.count(x)Returnthenumberoftimesxappearsinthelist.list.sort()Sorttheitemsofthelist,inplace.list.reverse()Reversetheelementsofthel

9、ist,inplace.Anexamplethatusesmostofthelistmethods:如下的例子用到了上述的大部分方法:a=[66.25,333,333,1,1234.5]printa.count(333),a.count(66.25),a.count('x')210a.insert(2,-1)a.append(333)a[66.25,333,-1,333,1,1234.5,333]a.index(333)1a.remove(333)a[66.25,-1,333,1,1234.5,333]a.reverse()a[333,1

10、234.5,1,333,-1,66.25]a.sort()a[-1,1,66.25,333,333,1234.5]5.1.1.UsingListsasStacks将list作为堆栈使用?Thelistmethodsmakeitveryeasytousealistasastack,wherethelastelementaddedisthefirstelementretrieved("last-in,first-out").Toaddanitemtothetopofthestack,useappend().Toretrieveanitemfr

11、omthetopofthestack,usepop()withoutanexplicitindex.Forexample:list的方法可以让List很轻易的变成一个堆栈来使用,而堆栈的特点就

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。