Data Structures in Python 🗃️: Lists, Tuples, Dictionaries, and Sets
Data structures are vital for organizing and manipulating data efficiently.
Lists: Ordered, mutable collections.
fruits = ['apple', 'banana', 'cherry']
fruits.append('date') # Adds element
print(fruits)
Tuples: Immutable ordered collections.
coordinates = (10.0, 20.0)
Dictionaries: Key-value pairs, highly flexible.
person = {'name': 'Alice', 'age': 30}
print(person['name']) # Output: Alice
Sets: Unordered collections with unique elements.
unique_numbers = {1, 2, 2, 3}
print(unique_numbers) # Output: {1, 2, 3}
Choosing appropriate data structures enhances performance and code clarity, especially when handling large data sets.