๐Ÿ Python Lists: Vectors of Indian Classrooms ๐Ÿ‡ฎ๐Ÿ‡ณ๐Ÿ“š

Prashant KumarPrashant Kumar
4 min read

Welcome to the most chaotic yet lovable data structure in Python โ€” lists! But wait โ€” to make this article 200% more relatable, weโ€™re going desi with a full-on Indian classroom vibe. If youโ€™ve ever stood in a roll call line wondering, โ€œWhy is Prashant always first?โ€, this blog is for you. ๐Ÿ˜‚

Whether you're a Python noob or someone who still writes print with capital P (guilty in 1st year ๐Ÿ˜…), lists (a.k.a vectors) are your loyal best friends in Python.


๐Ÿงบ What is a List?

A list is a collection of items. You can store names, numbers, even mixed things in it.

Example:

# ๐Ÿ“ฆ Vector (List) Basics in Python using Indian Names

# Meet our vector of friends โ€” think of this like a row of chairs in a classroom!
students = ["Prashant", "Priya", "Sidharth", "Anirudh"]

# ๐Ÿงพ Printing the entire list (aka roll call!)
print("Roll Call:", students)

๐Ÿ“ How to Access Items in List?

Each item in a list has a position number, called an index. It starts from 0.

# ๐ŸŽฏ Accessing specific students by index (starting from 0)
print("First student:", students[0])     # Output: Prashant
print("Last student:", students[-1])     # Output: Anirudh

โž• How to Add an Item to a List?

If someone new joins the class, we can add them using .append().

# โž• Adding a new student to the list
students.append("Meera")
print("After adding Meera:", students)

๐Ÿงน How to Remove an Item from a List?

If someone bunks the class ๐Ÿ˜…, we can remove them.

# ๐Ÿงน Removing someone who bunked class
students.remove("Sidharth")
print("After removing Sidharth:", students)

๐Ÿ” How to Change a Name in the List?

If a name is wrong or changed, we can update it.

# ๐Ÿ”„ Changing Priya to Simran
students[students.index("Priya")] = "Simran"
print("After changing Priya to Simran:", students)

๐Ÿ“ How to Count How Many Students?

Just use len() function.

# ๐Ÿ“ Total number of students
print("Total students in class:", len(students))

๐Ÿ” Loop Through All Names (One by One)

Sometimes, we want to greet or print all names.

# ๐Ÿ” Saying Hello to everyone
for name in students:
    print(f"Hello, {name}!")

๐Ÿชช With Roll Numbers (Using Loop + Index)

We can also print names with numbers.

# ๐Ÿชช Roll numbers with names
for i, name in enumerate(students, start=1):
    print(f"Roll No. {i}: {name}")

๐Ÿ” Check if Someone is Present

You can use in to check if someone is on the list.

# ๐Ÿ” Is Anirudh present?
if "Anirudh" in students:
    print("Anirudh is present!")
else:
    print("Anirudh is absent.")

๐ŸŽ‚ Birthday Example โ€“ Invite Your Friends

Letโ€™s use list for real-life example: birthday invites.

# ๐ŸŽˆ Making a birthday invite list
birthday_invites = ["Prashant", "Meera", "Simran"]

# ๐ŸŽ‰ Sending invites
for friend in birthday_invites:
    print(f"Invitation sent to {friend}!")

Want to change someone on the list?

# ๐Ÿ” Changing Meera to Tanmay
birthday_invites[birthday_invites.index("Meera")] = "Tanmay"
print("Updated invite list:", birthday_invites)

๐Ÿ’พ Copy the List (Backup Time)

Sometimes, we want to keep a copy before changing anything.

# ๐Ÿ’พ Copy the student list
backup_list = students.copy()
print("Backup list:", backup_list)

๐Ÿ“š Sorting and Reversing the List

We can arrange names A to Z or reverse the order.

# ๐Ÿ“š Sorting names A-Z
students.sort()
print("Sorted students:", students)

# ๐Ÿ” Reversing the list
students.reverse()
print("Reversed students:", students)

๐Ÿ˜ต Common Mistakes (Be Careful!)

  1. IndexError โ€” If you try to access a position that doesnโ€™t exist:
# print(students[10])  # โŒ This will give an error
  1. ValueError โ€” If you try to remove someone who is not in list:

    ๐Ÿ”š Wrapping It Up

    Python lists arenโ€™t just a feature โ€” theyโ€™re a vibe. Easy to use, endlessly flexible, and perfect for making your code look smarter than you on a Monday morning.

    Remember, a good coder doesnโ€™t just learn syntax โ€” they connect it with real life. So next time you attend a class, just look around and think: โ€œDamn, this is literally a list.โ€

    Keep coding and stay spicy ๐ŸŒถ๏ธ โ€” like Maggi in hostel.

    ๐Ÿš€ Until next time, list lovers!

1
Subscribe to my newsletter

Read articles from Prashant Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prashant Kumar
Prashant Kumar