Python Data Structure and Algorithms For Cracking Coding Interviews π
Algorithms and data structures are fundamental to efficient code and good software design. Creating and designing excellent algorithms is required for being an exemplary programmer. This repository's goal is to demonstrate how to correctly implement common data structures and algorithms in the simplest and most elegant ways.
B
- Beginner, A
- Advanced
B
List
Lists are one of the fundamental built-in data types in python. They are collection of items which internally uses Array Data Structures.
However unlike in languages like C++, . Also, Python Lists allows us to store . Here are some properties of python lists :
- Python Lists are dynamic in nature, meaning its size grows or shrinks according to data stored or deleted
- It is zero-indexed meaning that the first element has index 0
- It allows duplicate items
- It is ordered in nature
- It allows us to store different data types in a single list itself
A = [20,40,60,10,20]
In the above code the, first element of "A" is 20 and its index is 0, second element of "A" is 40 and its index is 1, third element of "A" is 60 and its index is 2, fourth element of "A" is 10 and its index is 3, fifth element of "A" is 20 and its index is 4
A = [20,40,60,10,20]
# Accessing the 1st element
print(A[0])
# Accessing element 60
print(A[2])
20
60
A = [20,40,60,10,20]
# Changing the element 40 to say 100 or
A[1] = 100
print(A)
# Changing the 3rd element to 90
A[2] = 90
print(A)
[20, 100, 60, 10, 20]
[20, 100, 90, 10, 20]