Ever wondered how some programmers take one look at a problem and immediately know what code to write? I will let you in on the secret. It is all about data structures. Let's explore this secret more closely.
The data structure is simply the structure used to hold data together and so to manipulate any data ( programming ) you first need to know what structure that data is in and then use the structures methods accordingly.
There are four built-in data structures in Python:
- List - ordered mutable
- Tuple - ordered immutable
- Dictionary - mutable key/value pair
- Set - mutable unordered unique cannot contain mutable types
LIST DATA STRUCTURE
A list is a data structure that holds a collection of ordered/sequence mutable items.
A list in python is created with square brackets containing comma-separated-values, you cannot miss it once you see one, below is an example of a list stored within a variable called fruits.
Example:
list = [1, 2, 3]
When to use List
Below are some reasons why you might need to use the list data structure instead.
- You are dealing with sequenced data
- Order might be of importance
- Need to change the list (mutate)
- The list is homogeneous ( same type of data )
For how to create and use list, with some examples checkout:
Python Tuple Data Structure Practical Example
To read the post in full details:
Read Full Article...
Top comments (0)