Working with Lists
A list is an ordered collection of items. Instead of creating separate variables for each stock in a portfolio, you can store them all in a single list.
Creating Lists
Loading Python Playground...
Accessing List Elements
Lists are indexed starting from 0 (the first item is at position 0):
Loading Python Playground...
Modifying Lists
Lists are mutable - you can change their contents:
Loading Python Playground...
Useful List Operations
Loading Python Playground...
List Slicing
Extract portions of a list:
Loading Python Playground...
Sorting Lists
Loading Python Playground...
Practice: Portfolio Analysis
Loading Python Exercise...
Practice: Calculate Portfolio Value
Loading Python Exercise...
Key Takeaways
- Lists store ordered collections of items
- Access elements with
[index], starting from 0 - Negative indices count from the end:
[-1]is the last item - Use
append()to add items,remove()to delete len(),sum(),max(),min()work on lists- Slice with
[start:end]to extract portions sorted()creates a sorted copy,.sort()modifies in place
Next, we'll learn about dictionaries - storing data with meaningful labels like ticker symbols!

