# Chapter 4: Collections, Indexing, and Slicing
# Fundamentals of Python for Financial Econometrics - Collections, Indexing, and Slicing
# Dataset: Ceteris Lab teaching sample

# Collections, Indexing, and Slicing
#
# **Opening question:** How should related values be organized so that the structure communicates what operations are legitimate?

# %% Cell 2
returns = [0.012, -0.004, 0.009, 0.003, -0.011]
print(returns[0])
print(returns[-1])
print(returns[1:4])

# **Interpretation check:** Interpretation. The slice includes positions 1, 2, and 3, but not 4.

# %% Cell 4
weights = {"BOND": 0.50, "EQUITY": 0.35, "CASH": 0.15}
print(sum(weights.values()))
large_positions = [asset for asset, w in weights.items() if w >= 0.30]
print(large_positions)

# **Interpretation check:** Interpretation. A dictionary preserves the relationship between each asset label and its weight.

# %% Cell 6
print(returns[0])
print(returns[-1])
print(returns[1:4])
print(sum(weights.values()))
large_positions = [asset for asset, w in weights.items() if w >= 0.30]
print(large_positions)

# Verified source output
#
# ```text
# 0.012 -0.011 [-0.004, 0.009, 0.003]
# ```
#
# ```text
# 1.0 ['BOND', 'EQUITY']
# ```
#
# ```text
# 0.012
# -0.011
# [-0.004, 0.009, 0.003]
# ```
#
# ```text
# 1.0
# ['BOND', 'EQUITY']
# ```
