Python data structures
Improve this article..
What data structures in Python are immutable?
Immutable data types: These are datatypes which can't be changed in place after declaration.All basic datatypes such as int,string come under this basket.
Now coming to which data structutes in Python are immutable?
These are the immutable data structures we encounter in Python:
tuple(), frozenset(), bytes()
Tip: To know if a data structure is mutable or not, id() built-in function.
What data structures in Python are suited to handle binary data?
The core built-in types for manipulating binary data are bytes and bytearray. They are supported by memoryview which uses the buffer protocol to access the memory of other binary objects without needing to make a copy.
The array module supports efficient storage of basic data types like 32-bit integers and IEEE754 double-precision floating values.
What sequences are available in Python?
Sequences types in Python are data types that have inherent ordering among their items. Their items can be accessed using indices. For example, the string
str = "hello world"
is a sequence of Unicode characters h, e, l, etc. The first item of this string is accessed using the expression
. Note that there is no character data type in Python, and the expression evaluates to a string "h".
How can I implement a linked list in Python?
Linked list is a collection of nodes connected by links.A linked list is considered a recursive data structure
because it has a recursive definition.
A node is single data point in the linked list. It not only holds the data stored,
but also has a pointer that can tell which the next node is in single linked list where as two pointers in doubly linked list.
Technically, you can implement your own linked list only using node. As long as you know which node is the head,
you can do everything with the whole list, such as add, search, delete, etc.
How can I implement a tree or a graph in Python? What should I consider when selecting a data structure?