Table of Contents

ListsTuples
1. Introduction to Lists1. Introduction to Tuples
– Definition and characteristics– Definition and characteristics
– Mutable nature– Immutable nature
2. Basic Operations2. Creating and Accessing Tuples
– Creating lists– Tuple creation syntax
– Accessing elements– Indexing and accessing elements
– Modifying elements
3. Tuple Packing and Unpacking
3. Common Methods– Explanation and examples
append() and extend()
insert() and remove()4. Common Operations
pop() and clear()– Concatenating tuples
– Converting tuples to lists and vice versa
4. Iterating over Lists
– Using for loops5. Iterating over Tuples
– List comprehensions– Using for loops
5. Slicing and Indexing6. Advantages of Tuples
– Indexing basics– Performance benefits
– Slicing syntax and examples– Use cases
6. List Manipulation Techniques7. Comparison with Lists
– Sorting lists– Differences in mutability and usage
– Reversing lists
– Concatenating lists8. Best Practices
– When to use tuples over lists
7. Nested Lists– Maintaining data integrity
– Definition and usage
– Accessing elements in nested lists
Conclusion
8. Best Practices– Recap of key differences
– Efficiency considerations– Recommendations for practical usage
– Pythonic coding style

Lists in Python

Definition: Lists are ordered collections of items, mutable (modifiable after creation), and can contain elements of different data types.

# Creating a list
my_list = [1, 2, 3, 'a', 'b', 'c']

# Accessing elements
print(my_list[0])  # Output: 1
print(my_list[3])  # Output: 'a'

# Modifying elements
my_list[1] = 10
print(my_list)  # Output: [1, 10, 3, 'a', 'b', 'c']

# Adding elements
my_list.append('d')
print(my_list)  # Output: [1, 10, 3, 'a', 'b', 'c', 'd']

# Removing elements
removed_item = my_list.pop(2)
print(my_list)      # Output: [1, 10, 'a', 'b', 'c', 'd']
print(removed_item) # Output: 3

# Iterating over a list
for item in my_list:
    print(item)

# List slicing
print(my_list[1:4])  


Output:
[10, 'a', 'b']