|
@@ -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",
|
|
|
" )"
|
|
|
]
|
|
|
},
|