List Data Structure in 5 mins – Python

List Data Structure in 5 mins – Python

Hi developers/learners/readers 🙋‍♀️✋

Python Unleashed 07

Going to do comparison between C++ vectors and Python lists in this blog. As I am moving to Python from C++, so this can help others like me.

To those who are not familiar with C++, you may find few things confusing.

INTRO

List items are within square brackets, like C++ arrays/vector
Dynamically sized, can shrink and grow
elements are separated by comma as always
Stores data in sequence, in linear fashion
It can store data of any type, unlike vectors in C++
Random Access Possible (Negative and Positive Index), Prone to Index out of bound errors, AND ZERO BASED INDEXING
Mutable
We do have a list class for lists

List is so so much similar to vectors.

list[-0] returns 0th elements only

Methods on List

Append -> add element to the end of list, one at a time, tuple and lists can be added

Insert -> requires two values, element can be added at desired position. One argument is position, second is value.

Extend -> add multiple elements to the end of list, elements must be in square bracket.

Reverse -> reverses the list

Reversed -> A good read

Remove Elements -> Removes one element at a time, and element must be there in the list, otherwise throws error, pass element which you would like to delete

Pop -> Either remove element from end only or pass index

Slicing -> Same as that for strings check here strings
For more information check here

END

Thanks for reading

If you liked the content, do react, or for any feedback/correction/suggestion feel free to reach out to me on Linkedin or can comment here

Nice Day

Leave a Reply

Your email address will not be published. Required fields are marked *