Queer European MD passionate about IT
Explorar el Código

Py2 GP Solution Rewrite #Fix1

bruno hace 6 años
padre
commit
e208752d8b
Se han modificado 1 ficheros con 62 adiciones y 11 borrados
  1. 62 11
      Mission356Solutions.ipynb

+ 62 - 11
Mission356Solutions.ipynb

@@ -234,7 +234,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 18,
+   "execution_count": 6,
    "metadata": {},
    "outputs": [
     {
@@ -266,7 +266,7 @@
        " '11': 641}"
       ]
      },
-     "execution_count": 18,
+     "execution_count": 6,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -367,6 +367,65 @@
    "cell_type": "code",
    "execution_count": 8,
    "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "[[5.5777777777777775, '09'], [14.741176470588234, '13'], [13.440677966101696, '10'], [13.233644859813085, '14'], [16.796296296296298, '16'], [7.985294117647059, '23'], [9.41095890410959, '12'], [11.46, '17'], [38.5948275862069, '15'], [16.009174311926607, '21'], [21.525, '20'], [23.810344827586206, '02'], [13.20183486238532, '18'], [7.796296296296297, '03'], [10.08695652173913, '05'], [10.8, '19'], [11.383333333333333, '01'], [6.746478873239437, '22'], [10.25, '08'], [7.170212765957447, '04'], [8.127272727272727, '00'], [9.022727272727273, '06'], [7.852941176470588, '07'], [11.051724137931034, '11']]\n"
+     ]
+    },
+    {
+     "data": {
+      "text/plain": [
+       "[[38.5948275862069, '15'],\n",
+       " [23.810344827586206, '02'],\n",
+       " [21.525, '20'],\n",
+       " [16.796296296296298, '16'],\n",
+       " [16.009174311926607, '21'],\n",
+       " [14.741176470588234, '13'],\n",
+       " [13.440677966101696, '10'],\n",
+       " [13.233644859813085, '14'],\n",
+       " [13.20183486238532, '18'],\n",
+       " [11.46, '17'],\n",
+       " [11.383333333333333, '01'],\n",
+       " [11.051724137931034, '11'],\n",
+       " [10.8, '19'],\n",
+       " [10.25, '08'],\n",
+       " [10.08695652173913, '05'],\n",
+       " [9.41095890410959, '12'],\n",
+       " [9.022727272727273, '06'],\n",
+       " [8.127272727272727, '00'],\n",
+       " [7.985294117647059, '23'],\n",
+       " [7.852941176470588, '07'],\n",
+       " [7.796296296296297, '03'],\n",
+       " [7.170212765957447, '04'],\n",
+       " [6.746478873239437, '22'],\n",
+       " [5.5777777777777775, '09']]"
+      ]
+     },
+     "execution_count": 8,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "swap_avg_by_hour = []\n",
+    "\n",
+    "for row in avg_by_hour:\n",
+    "    swap_avg_by_hour.append([row[1], row[0]])\n",
+    "    \n",
+    "print(swap_avg_by_hour)\n",
+    "\n",
+    "sorted_swap = sorted(swap_avg_by_hour, reverse=True)\n",
+    "\n",
+    "sorted_swap"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -384,16 +443,8 @@
    "source": [
     "# Sort the values and print the the 5 hours with the highest average comments.\n",
     "\n",
-    "def sort_by_2nd_column(to_sort):\n",
-    "    return to_sort[1]\n",
-    "\n",
-    "avg_by_hour = sorted(avg_by_hour,\n",
-    "                     key=sort_by_2nd_column,\n",
-    "                     reverse=True\n",
-    "                    )\n",
-    "\n",
     "print(\"Top 5 Hours for 'Ask HN' Comments\")\n",
-    "for hr, avg in avg_by_hour[:5]:\n",
+    "for avg, hr in sorted_swap[:5]:\n",
     "    print(\n",
     "        \"{}: {:.2f} average comments per post\".format(\n",
     "            dt.datetime.strptime(hr, \"%H\").strftime(\"%H:%M\"),avg\n",