Skip to main content

Command Palette

Search for a command to run...

Python Data Structures: Imagine If They Were People at a Party.

Published
2 min readView as Markdown
Python Data Structures: Imagine If They Were People at a Party.

1. Lists – The Chill Friend Who Brings Everyone and Their Cousins.

Lists are like that one guy at a party who brings people, forgets who he invited, changes the playlist mid-way, and adds a few last-minute snacks.

Behavior:

  • Ordered like a guest list.(Fav guests on TOP)

  • Mutable — keeps changing his mind.(Some Relatives just don’t deserve)

  • Duplicates allowed — brings 2 Deep? No problem.(My Unique friendships)

party_guests = ["Ashwin", "Manjeet", "Sambhav"]
party_guests.append("Deepak")         # more guests!
party_guests[1] = "Mandeep"             # name change
party_guests.remove("Ashwin")          # kicked out

2. Tuples – The Grandma Who Doesn’t Change Anything

Tuples are like your grandma’s living room — you don’t touch anything. The chairs have been there since 1994, and you will get a look if you try moving one. :) :)

Behavior:

  • Ordered — she knows exactly where everything goes (obviously she is perfect).

  • Immutable — “Don’t even think about changing that!” (I have no guts!!)

  • Duplicates? Sure, if grandma put two identical vases, that’s her business.(Leaving on her).

living_room = ("sofa", "lamp", "TV", "sofa")
print(living_room[1])         # lamp
# living_room[1] = "plant"   # Grandma said NO.

3. Dictionaries – The “UNCLE” With a Guest List and Secrets

A dictionary is like a “UNCLE” with a clipboard — names (keys) on the list, info (values) behind the scenes. Try asking for someone who’s not on the list — And you just can’t by pass his eyes….

Behavior:

  • Key-value pairs — Name + Phone Number (He like confirmations)

  • Keys must be unique — two “Rahuls”? Nope, one Rahul only.(Don’t like Rahuls)

  • Mutable — add, remove, or update any entry.(ahh, He is that only good).

guest_info = {
  "Mandeep": "Programmer",
  "Aisha": "Designer"
}
guest_info["Sam"] = "Musician"
del guest_info["Aisha"]

4. Sets – The Anti-Drama Friend Who Hates Repeats.

A set is like a no-nonsense minimalist — “You already told that joke, move on.” Try repeating a story? "Ignored” . Try adding “banana” twice? Still one banana…

Behavior:

  • Unordered — throws out your fancy order. (don’t care)

  • No duplicates allowed (don’t just like repeating things)

  • Mutable — but selective.(Selecticism : even I don’t know what it means)

snack_bowl = {"apple", "banana", "apple", "mango"}
print(snack_bowl)  # Only one apple. Sorry.
snack_bowl.add("kiwi")

And this is How Party ends with a relief that no one touched grandma’s things.

So give me permission to go also , it’s too late….

Bye :) Meet you in some other blogs.