回复内容:
- Python 的 list 是怎么回事,为什么有近乎无限大小的空间?为什么专门有一个固定长度且不能修改的数据结构 tuple 而不全用 list?
- list 的 insert 和 append 的费时是一样的吗?
- Python 的 dict 是怎么回事,为什么可以用字符串数字等等东西来索引?是怎么搜索的?在 dict 中找一个元素,和在 list 里面找一个元素有什么区别?
- Python 内置的 list, dict, set, ...数据结构,你应该在什么样的场景下使用?
- 小明家大姨开了小卖部,觉得小明是学编程的各种高大上,需要用 Python 写一个找零钱的程序,输入任意整数,输出如何找零钱需要的张数最少,小明应该如何写?
“虽然当下大部分流行的高级语言都自带了对常用数据结构的支持,而且多半你无法给出更加优秀的实现,但是继续学习数据结构的动力在于:它让你学会选择一个正确且合适的数据结构去解决一个具体的问题。”
尤其是Python这样的语言,built-in的这些数据结构:list, dict, set...似乎是万能的(的确,有些时候确实是万能的)。但如果你了解它们背后的具体实现,就会发现,看似完美的数据结构,却未必是合适之选。比如内存空间惜“字”如金,主要目的是顺序存取,而完全不需要动态扩展的情况下,list就没有传统的array合适,具体的原因可以去了解一下list的实现原理。
推荐一本书吧:《Data Structures and Algorithms Using Python》,网上可以下载到高清的pdf。书中除了讲述了几种常用数据结构栈、队列、二叉树等的Python实现,特别值得推荐的是,还对Python的几个built-in数据结构的实现进行了具体的分析。相信会有帮助。唯一不足的是,只有英文版的,耐心读一下吧,会有一种豁然开朗的感觉。
+++++++++++++++++++++++++++分割线+++++++++++++++++++++++++++++++++
补充:
这本书后面部分的样例代码有点混乱,混杂了Python 2.x 和 Python 3.x ,需要留意区分一下。
附上一个下载链接吧:
Data Structures and Algorithms Using Python.pdf_免费高速下载 python程序员学习路线图 python+ 数据结构和算法 + linux + 软件工程 + web开发 + git版本控制+ 沟通技巧等等。 当然不是。这么明显的问题还用问吗? Python是种语言。
数据结构和算法教你如何高效的使用各种语言。
所以如果想高效使用Python,是需要学算法和数据结构。

pythonisehybridmodelofcompilationand interpretation:1)thepythoninterspretercompilesourcececodeintoplatform- interpententbybytecode.2)thepytythonvirtualmachine(pvm)thenexecuteCutestestestesteSteSteSteSteSteSthisByTecode,BelancingEaseofuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允许fordingfordforderynamictynamictymictymictymictyandrapiddefupment,尽管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知识之际,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations则youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concateNateListsinpythonwithTheSamelements,使用:1)operatototakeepduplicates,2)asettoremavelemavphicates,or3)listCompreanspearensionforcontroloverduplicates,每个methodhasdhasdifferentperferentperferentperforentperforentperforentperfortenceandordormplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允许ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能