


"""simple docstring"""







from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset




class 			UpperCamelCase_     (			lowerCAmelCase_):

	"""simple docstring"""





	def   UpperCAmelCase_				(			self      :    Any       )	->     str:
						return [
						    {"col_1": 3, "col_2": "a"},
						    {"col_1": 2, "col_2": "b"},
						    {"col_1": 1, "col_2": "c"},
						    {"col_1": 0, "col_2": "d"},
						]




	def   UpperCAmelCase_				(			self      :    str       )	->     Dict:
						__SCREAMING_SNAKE_CASE						       =    {"col_1": [3, 2, 1, 0], "col_2": ["a", "b", "c", "d"]}
						return Dataset.from_dict(__SCREAMING_SNAKE_CASE       )




	def   UpperCAmelCase_				(			self      :    int       )	->     Optional[Any]:
						__SCREAMING_SNAKE_CASE						       =    self._create_example_records()
						__SCREAMING_SNAKE_CASE						       =    Dataset.from_list(__SCREAMING_SNAKE_CASE       )
						self.assertListEqual(dset.column_names      ,      ["col_1", "col_2"]       )
						for i, r in enumerate(__SCREAMING_SNAKE_CASE       ):
											self.assertDictEqual(__SCREAMING_SNAKE_CASE      ,      example_records[i]       )




	def   UpperCAmelCase_				(			self      :    List[Any]       )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    self._create_example_records()
						__SCREAMING_SNAKE_CASE						       =    Dataset.from_list(__SCREAMING_SNAKE_CASE       )
						__SCREAMING_SNAKE_CASE						       =    Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]}       )
						self.assertEqual(dset.info      ,      dset_from_dict.info       )




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     List[Any]:  # checks what happens with missing columns
						__SCREAMING_SNAKE_CASE						       =    [{"col_1": 1}, {"col_2": "x"}]
						__SCREAMING_SNAKE_CASE						       =    Dataset.from_list(__SCREAMING_SNAKE_CASE       )
						self.assertDictEqual(dset[0]      ,      {"col_1": 1}       )
						self.assertDictEqual(dset[1]      ,      {"col_1": None}       )  # NB: first record is used for columns




	def   UpperCAmelCase_				(			self      :    int       )	->     List[Any]:  # checks if the type can be inferred from the second record
						__SCREAMING_SNAKE_CASE						       =    [{"col_1": []}, {"col_1": [1, 2]}]
						__SCREAMING_SNAKE_CASE						       =    Dataset.from_list(__SCREAMING_SNAKE_CASE       )
						self.assertEqual(dset.info.features["col_1"]      ,      Sequence(Value("int64"       )       )       )




	def   UpperCAmelCase_				(			self      :    Tuple       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    Dataset.from_list([]       )
						self.assertEqual(len(__SCREAMING_SNAKE_CASE       )      ,      0       )
						self.assertListEqual(dset.column_names      ,      []       )









"""simple docstring"""







from __future__ import annotations

import requests




def        UpperCAmelCase__	(lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    f"""https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty"""
					return requests.get(lowerCAmelCase_       ).json()




def        UpperCAmelCase__	(lowerCAmelCase_ = 10       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
					__SCREAMING_SNAKE_CASE						       =    requests.get(lowerCAmelCase_       ).json()[:max_stories]
					return [get_hackernews_story(lowerCAmelCase_       ) for story_id in story_ids]




def        UpperCAmelCase__	(lowerCAmelCase_ = 10       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    hackernews_top_stories(lowerCAmelCase_       )
					return "\n".join("* [{title}]({url})".format(**lowerCAmelCase_       ) for story in stories       )


if __name__ == "__main__":
		print(hackernews_top_stories_as_markdown())
