search
HomeBackend DevelopmentPython Tutorial有了 Python 是不是不需要学数据结构,算法了?

回复内容:

  • 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,是需要学算法和数据结构。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python's Execution Model: Compiled, Interpreted, or Both?Python's Execution Model: Compiled, Interpreted, or Both?May 10, 2025 am 12:04 AM

Pythonisbothcompiledandinterpreted.WhenyourunaPythonscript,itisfirstcompiledintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).Thishybridapproachallowsforplatform-independentcodebutcanbeslowerthannativemachinecodeexecution.

Is Python executed line by line?Is Python executed line by line?May 10, 2025 am 12:03 AM

Python is not strictly line-by-line execution, but is optimized and conditional execution based on the interpreter mechanism. The interpreter converts the code to bytecode, executed by the PVM, and may precompile constant expressions or optimize loops. Understanding these mechanisms helps optimize code and improve efficiency.

What are the alternatives to concatenate two lists in Python?What are the alternatives to concatenate two lists in Python?May 09, 2025 am 12:16 AM

There are many methods to connect two lists in Python: 1. Use operators, which are simple but inefficient in large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use the = operator, which is both efficient and readable; 4. Use itertools.chain function, which is memory efficient but requires additional import; 5. Use list parsing, which is elegant but may be too complex. The selection method should be based on the code context and requirements.

Python: Efficient Ways to Merge Two ListsPython: Efficient Ways to Merge Two ListsMay 09, 2025 am 12:15 AM

There are many ways to merge Python lists: 1. Use operators, which are simple but not memory efficient for large lists; 2. Use extend method, which is efficient but will modify the original list; 3. Use itertools.chain, which is suitable for large data sets; 4. Use * operator, merge small to medium-sized lists in one line of code; 5. Use numpy.concatenate, which is suitable for large data sets and scenarios with high performance requirements; 6. Use append method, which is suitable for small lists but is inefficient. When selecting a method, you need to consider the list size and application scenarios.

Compiled vs Interpreted Languages: pros and consCompiled vs Interpreted Languages: pros and consMay 09, 2025 am 12:06 AM

Compiledlanguagesofferspeedandsecurity,whileinterpretedlanguagesprovideeaseofuseandportability.1)CompiledlanguageslikeC arefasterandsecurebuthavelongerdevelopmentcyclesandplatformdependency.2)InterpretedlanguageslikePythonareeasiertouseandmoreportab

Python: For and While Loops, the most complete guidePython: For and While Loops, the most complete guideMay 09, 2025 am 12:05 AM

In Python, a for loop is used to traverse iterable objects, and a while loop is used to perform operations repeatedly when the condition is satisfied. 1) For loop example: traverse the list and print the elements. 2) While loop example: guess the number game until you guess it right. Mastering cycle principles and optimization techniques can improve code efficiency and reliability.

Python concatenate lists into a stringPython concatenate lists into a stringMay 09, 2025 am 12:02 AM

To concatenate a list into a string, using the join() method in Python is the best choice. 1) Use the join() method to concatenate the list elements into a string, such as ''.join(my_list). 2) For a list containing numbers, convert map(str, numbers) into a string before concatenating. 3) You can use generator expressions for complex formatting, such as ','.join(f'({fruit})'forfruitinfruits). 4) When processing mixed data types, use map(str, mixed_list) to ensure that all elements can be converted into strings. 5) For large lists, use ''.join(large_li

Python's Hybrid Approach: Compilation and Interpretation CombinedPython's Hybrid Approach: Compilation and Interpretation CombinedMay 08, 2025 am 12:16 AM

Pythonusesahybridapproach,combiningcompilationtobytecodeandinterpretation.1)Codeiscompiledtoplatform-independentbytecode.2)BytecodeisinterpretedbythePythonVirtualMachine,enhancingefficiencyandportability.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment