    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Algorithm\n",
      "\n",
      "Return the input, val\n",
      "    \n",
      "Complexity:\n",
      "* Time: O(1)\n",
 
</s> remove     "* Time: O(1)\n",
    "* Space: O(1)"
 </s> add     "* Time: O(n^2)\n",
    "* Space: O(n)" </s> remove     "Return the input, val\n",
 </s> add     "* Save the relative position of the first-occurence of each item in a list.\n",
    "* Iterate through list of unique items.\n",
    "    * Keep an outer index; scan rest of list, swapping matching items with outer index and incrementing outer index each time. \n", </s> remove     "## Problem: Implement foo(val), which returns val\n",
 </s> add     "## Problem: Implement a function that groups identical items based on their order in the list.\n", </s> remove 
    "* Is it foo or bar?\n",
    "    * foo"
 </s> add     "* Can we use extra data structures?\n",
    "    * Yes" </s> remove     "def foo(val):\n",
    "    return val"
 </s> add     "def make_order_list(list_in):\n",
    "    order_list = []\n",
    "    for item in list_in:\n",
    "        if item not in order_list:\n",
    "            order_list.append(item)\n",
    "    return order_list\n",
    "\n",
    "\n",
    "def group_ordered(list_in):\n",
    "    if list_in is None:\n",
    "        return None\n",
    "    order_list = make_order_list(list_in)\n",
    "    current = 0\n",
    "    for item in order_list:\n",
    "        search = current + 1\n",
    "        while True:\n",
    "            try:\n",
    "                if list_in[search] != item:\n",
    "                    search += 1\n",
    "                else:\n",
    "                    current += 1\n",
    "                    list_in[current], list_in[search] = list_in[search], list_in[current]\n",
    "                    search += 1\n",
    "            except IndexError:\n",
    "                break\n",
    "    return list_in"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Algorithm: Ordered Dict.\n",
    "\n",
    "* Use an ordered dict to track insertion order of each key\n",
    "* Flatten list of values.\n",
    "\n",
    "Complexity:\n",
    "\n",
    "* Time: O(n)\n",
    "* Space: O(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code: Ordered Dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from collections import OrderedDict\n",
    "\n",
    "def group_ordered(list_in):\n",
    "    result = OrderedDict()\n",
    "    for value in list_in:\n",
    "        result.setdefault(value, []).append(value)\n",
    "    return [v for group in result.values() for v in group]"
    "## Algorithm: Modified Selection Sort\n",
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
    "## Algorithm: Modified Selection Sort\n",
      "\n",
      "Return the input, val\n",
      "    \n",
      "Complexity:\n",
      "* Time: O(1)\n",
keep keep keep keep replace keep keep keep keep keep
 added both solutions w/ test 
arrays_strings/group_items/group_ordered_solution.ipynb