Python Tricks - Common Data Structures in Python(0)

What’s something that every Python developer should practice and learn more about?

Data structures. They’re the fundamental constructs around which you build your programs. Each data structure provides a particular way of organizing data so it can be accessed efficiently, depending on your use case.
数据结构。每一种数据结构都提供一种特殊的方式去组织数据所以它可以根据你的使用目的高效地运行。

I believe that going back to the fundamentals always pays off for a programmer, regardless of their skill level or experience.
我相信回归基础对一个程序员来说总是值得的,如论他们的技巧水平还是经验。

Now, I don’t advocate that you should focus on expanding your data structures knowledge alone—the “failure mode” for that is getting stuck in theory la-la land and never shipping anything…
现在,我并不是宣扬你需要集中注意力在只是扩充你的数据结构知识,这样只能让你故步自封。

But I found that spending some time on brushing up your data structures (and algorithms) knowledge always pays off.
但是我发现花一些时间去温习数据结构和算法的知识总是有好处的。

Whether you do that with a tightly focused “sprint” for a few days, or as an ongoing project with little pockets of time here and there doesn’t really matter. Either way, I promise it’ll be time well spent.

Alright, so data structures in Python, eh? We’ve got lists, dicts, sets…umm. Stacks? Do we have stacks?

You see, the trouble is that Python ships with an extensive set of data structures in its standard library. However, sometimes the naming for them is a bit “off”.
你看,问题是在python1标准库里封装了数据结构的大集合。然而,有时候它们的命名却有些偏差。

It’s often unclear how even well-known “abstract data types” like a Stack correspond to a specific implementation in Python. Other languages like Java stick to a more “computer-sciency” and explicit naming scheme: A list isn’t just a “list” in Java—it’s either a LinkedList or an ArrayList.
通常不清楚,甚至像堆栈这样的著名“抽象数据类型”如何对应于Python中的特定实现。像Java这样的其他语言坚持一种更“计算机科学”和明确的命名方案:在java,列表不仅仅是一个“列表”,它既可以是链接列表,也可以是列表。

This makes it easier to recognize the expected behavior and the computational complexity of these types. Python favors a simpler and more “human” naming scheme, and I love it. In part, it’s what makes programming with Python so much fun.
python有更加简单的和更加人性化的命名方案。

But the downside is that even to experienced Python developers, it can be unclear whether the built-in list type is implemented as a linked list or a dynamic array. And the day will come when lacking this knowledge will cause them endless hours of frustration, or get them rejected in a job interview.
但是这样的话即使是老道的python程序员也会疑惑内置的list是链接列表实现的还是动态列表。

In this part of the book you’ll take a tour of the fundamental data structures and implementations of abstract data types (ADTs) built into Python and its standard library.

My goal here is to clarify how the most common abstract data types map to Python’s naming scheme and to provide a brief description for each. This information will also help you shine in Python coding interviews.

If you’re looking for a good book to brush up on your general data structures knowledge, I highly recommend Steven S. Skiena’s The Algorithm Design Manual.

推荐了一本书:Steven S. Skiena的算法设计手册

It strikes a great balance between teaching you fundamental (and more advanced) data structures, and then showing you how to put them to practical use in various algorithms. Steve’s book was a great help in the writing of these chapters.

你可能感兴趣的:(Python Tricks - Common Data Structures in Python(0))