{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Collections, Indexing, and Slicing\n",
        "\n**Opening question:** How should related values be organized so that the structure communicates what operations are legitimate?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "returns = [0.012, -0.004, 0.009, 0.003, -0.011]\n",
        "print(returns[0])\n",
        "print(returns[-1])\n",
        "print(returns[1:4])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The slice includes positions 1, 2, and 3, but not 4.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "weights = {\"BOND\": 0.50, \"EQUITY\": 0.35, \"CASH\": 0.15}\n",
        "print(sum(weights.values()))\n",
        "large_positions = [asset for asset, w in weights.items() if w >= 0.30]\n",
        "print(large_positions)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. A dictionary preserves the relationship between each asset label and its weight.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print(returns[0])\n",
        "print(returns[-1])\n",
        "print(returns[1:4])\n",
        "print(sum(weights.values()))\n",
        "large_positions = [asset for asset, w in weights.items() if w >= 0.30]\n",
        "print(large_positions)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n0.012 -0.011 [-0.004, 0.009, 0.003]\n```\n\n```text\n1.0 ['BOND', 'EQUITY']\n```\n\n```text\n0.012\n-0.011\n[-0.004, 0.009, 0.003]\n```\n\n```text\n1.0\n['BOND', 'EQUITY']\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3"
    },
    "ceteris_lab": {
      "course_slug": "fundamentals-python-econometrics",
      "source_derived": true,
      "course_title": "Fundamentals of Python for Financial Econometrics",
      "chapter": 4,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
