Queer European MD passionate about IT
Browse Source

Update Mission356Solutions.ipynb

acstrahl 4 tháng trước cách đây
mục cha
commit
3d399e1ef0
1 tập tin đã thay đổi với 3 bổ sung5 xóa
  1. 3 5
      Mission356Solutions.ipynb

+ 3 - 5
Mission356Solutions.ipynb

@@ -75,8 +75,8 @@
     "# Read in the data.\n",
     "import csv\n",
     "\n",
-    "f = open('hacker_news.csv')\n",
-    "hn = list(csv.reader(f))\n",
+    "with open('hacker_news.csv') as f:\n",
+    "    hn = list(csv.reader(f))\n",
     "hn[:5]"
    ]
   },
@@ -446,9 +446,7 @@
     "print(\"Top 5 Hours for 'Ask HN' Comments\")\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",
-    "        )\n",
+    "        f\"{dt.datetime.strptime(hr, '%H').strftime('%H:%M')}: {avg:.2f} average comments per post\"\n",
     "    )"
    ]
   },