๐ ๐ฏ Lists and Tuples through a Bucket List Adventure!#
Get ready to learn how to organize your dreams in Python! ๐
Objectives:#
Master the art of list-making in Python ๐
Discover the unbreakable nature of tuples ๐
Compare lists and tuples to choose your perfect bucket list tool โ๏ธ
Build and manage your own digital bucket list ๐
Syntax
Lists:
Created with square brackets
[]
Perfect for your evolving dreams!
Example:
my_adventures = ["climb Mt. Everest", "learn salsa", 2024]
Syntax
Tuples:
Created with parentheses
()
Great for your achieved dreams!
Example:
completed_adventures = ("run marathon", "learn Python", 2023)
๐ Lists vs Tuples: Choose Your Adventure Tool!#
List: Your dynamic dream journal - ordered, changeable, and allows duplicate dreams (because some dreams are worth doing twice!)
Definition
Tuple: Your achievement trophy case - ordered, unchangeable, and allows duplicate accomplishments (because some achievements deserve multiple mentions!)
๐ Lists: Your Dynamic Dream Planner#
Letโs start with a bucket list that can grow and change, just like your dreams!
bucket_list = [
"Scuba dive with dolphins ๐ฌ",
"Make authentic Italian pizza ๐",
"Learn to juggle fire ๐ฅ",
]
print("My Adventure Wishlist:", bucket_list)
My Adventure Wishlist: ['Scuba dive with dolphins ๐ฌ', 'Make authentic Italian pizza ๐', 'Learn to juggle fire ๐ฅ']
Adding More Dreams! โญ#
# Let's add more exciting adventures!
bucket_list.append("Dance under the Northern Lights ๐ ")
bucket_list.append("Plant a garden and grow my own food ๐ฑ")
print("Updated Adventure List:", bucket_list)
Updated Adventure List: ['Scuba dive with dolphins ๐ฌ', 'Make authentic Italian pizza ๐', 'Learn to juggle fire ๐ฅ', 'Dance under the Northern Lights ๐ ', 'Plant a garden and grow my own food ๐ฑ']
๐ Tuples: Your Hall of Fame#
For those amazing achievements youโve already conquered:
completed_dreams = ("Run a marathon ๐โโ๏ธ", "Learn to make sushi ๐ฑ", "Adopt a pet ๐ฑ")
print("My Conquered Adventures:", completed_dreams)
My Conquered Adventures: ('Run a marathon ๐\u200dโ๏ธ', 'Learn to make sushi ๐ฑ', 'Adopt a pet ๐ฑ')
Why Choose Lists or Tuples? ๐ค#
Lists are like your dream journal:
โ๏ธ Can add new dreams anytime
๐ Can modify goals as they evolve
โ Can remove items that no longer spark joy
Tuples are like your trophy case:
๐ Permanently celebrate achievements
๐ Keep memories safely stored
โก Slightly faster performance (because memories shouldnโt change!)
What is Immutability?
Immutability means that an objectโs state cannot be modified after it is created. Tuples in Python are immutable, ensuring that once defined, their contents remain fixed. This makes them ideal for storing data that must remain constant, like keys in dictionaries or configuration settings.
Letโs Try Some Magic! โจ#
# Lists are flexible - you can change your mind!
bucket_list[0] = "Scuba dive with whales ๐" # Dreaming bigger!
print("Modified Dream:", bucket_list)
# Tuples are forever - just like achievements!
try:
completed_dreams[0] = "Run two marathons"
except TypeError as e:
print("๐ Achievement Locked:", e)
Modified Dream: ['Scuba dive with whales ๐', 'Make authentic Italian pizza ๐', 'Learn to juggle fire ๐ฅ', 'Dance under the Northern Lights ๐ ', 'Plant a garden and grow my own food ๐ฑ']
๐ Achievement Locked: 'tuple' object does not support item assignment
Pro Tip!
When you see a try/except block, think of it as a safety net for your code!
try: โLet me attempt this cool trick!โ
except: โOops, that didnโt work - hereโs why!โ
We will learn more about error handling and exceptions later in the course!
Organizing Your Life Goals ๐#
# Your achievement gallery
completed_bucket_list = ("Learn to code ๐ป", "Visit Grand Canyon ๐๏ธ")
# Your future adventures
pending_dreams = ["Write a novel ๐", "Learn to surf ๐โโ๏ธ", "Start a YouTube channel ๐ฅ"]
print("โ
Conquered Dreams:", completed_bucket_list)
print("๐ฏ Future Adventures:", pending_dreams)
โ
Conquered Dreams: ('Learn to code ๐ป', 'Visit Grand Canyon ๐๏ธ')
๐ฏ Future Adventures: ['Write a novel ๐', 'Learn to surf ๐\u200dโ๏ธ', 'Start a YouTube channel ๐ฅ']
Conclusion: Your Adventure Awaits! ๐#
Remember:
Use lists when your dreams are still evolving (like that travel wishlist that keeps growing!)
Use tuples to preserve your proudest moments (like running your first marathon!)
Keep dreaming big and coding bigger! ๐
Final Thought
Every great adventure begins with a single line of codeโฆ or a bucket list item! What will you add to yours? ๐ค