Binary Trees in Python
Jeff Schwab
jeffrey.schwab at rcn.com
Sun Aug 21 16:20:41 EDT 2005
Jorgen Grahn wrote:
> On Sat, 20 Aug 2005 15:19:55 -0400, Roy Smith <roy at panix.com> wrote:
>
>>In article <mailman.3314.1124564952.10512.python-list at python.org>,
>> [diegueus9] Diego Andrés Sanabria <zessa9 at gmail.com> wrote:
>>
>>
>>>Hello!!!
>>>
>>>I want know if python have binary trees and more?
>>
>>Python does not come with a tree data structure. The basic data structures
>>in Python are lists, tuples, and dicts (hash tables).
>>
>>People who are used to C++'s STL often feel short-changed because there's
>>not 47 other flavors of container, but it turns out that the three Python
>>gives you are pretty useful. Many people never find a need to look beyond
>>them.
>
>
> Uh, the STL has seven flavors:
> - vector
> - deque
> - list
> - set
> - map
> - multimap
> - multiset
There are others, e.g. std::valarray. There are also adapters that use
the above templates to implement other structures, adding or limiting
functionality as appropriate; e.g., std::heap and std::stack.
> so that's not too bad for a static language. Each of them
> is vital for some purpose, but vector and map are by far the
> most commonly used.
>
> Neither C++ nor Python has tree structures in their standard libraries. I
> assume that's because there is no single interface that is proven to suit
> everybody's needs.
Hmmm... I guess I never noticed the lack. C++ has structures or
language features that represent most of the common things trees are
typically used to implement. Of course, a "tree" can be represented in
so many ways, it's more of a design pattern than a data structure. :)
More information about the Python-list
mailing list