





'''simple docstring'''

from unittest import TestCase

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



class 		lowerCamelCase__      (						lowercase__     ):




					'''simple docstring'''



					def 						__UpperCAmelCase     (  self				:	str					)  ->       Any:



						'''simple docstring'''





						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				:	Optional[Any]					)  ->       Tuple:



						'''simple docstring'''





						_lowercase					:       Optional[int]       =		{"col_1": [3, 2, 1, 0], "col_2": ["a", "b", "c", "d"]}
						return Dataset.from_dict(UpperCamelCase_					)




					def 						__UpperCAmelCase     (  self				:	int					)  ->       Union[str, Any]:



						'''simple docstring'''





						_lowercase					:       List[str]       =		self._create_example_records()
						_lowercase					:       Optional[int]       =		Dataset.from_list(UpperCamelCase_					)
						self.assertListEqual(dset.column_names     ,  ['col_1', 'col_2']					)
						for i, r in enumerate(UpperCamelCase_					):
							self.assertDictEqual(UpperCamelCase_     ,  example_records[i]					)




					def 						__UpperCAmelCase     (  self				:	Any					)  ->       Union[str, Any]:



						'''simple docstring'''





						_lowercase					:       Tuple       =		self._create_example_records()
						_lowercase					:       Tuple       =		Dataset.from_list(UpperCamelCase_					)
						_lowercase					:       int       =		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				:	Optional[Any]					)  ->       List[Any]:  # checks what happens with missing columns



						'''simple docstring'''





						_lowercase					:       Optional[int]       =		[{"col_1": 1}, {"col_2": "x"}]
						_lowercase					:       List[Any]       =		Dataset.from_list(UpperCamelCase_					)
						self.assertDictEqual(dset[0]     ,  {'col_1': 1}					)
						self.assertDictEqual(dset[1]     ,  {'col_1': None}					)  # NB: first record is used for columns




					def 						__UpperCAmelCase     (  self				:	Tuple					)  ->       List[str]:  # checks if the type can be inferred from the second record



						'''simple docstring'''





						_lowercase					:       Any       =		[{"col_1": []}, {"col_1": [1, 2]}]
						_lowercase					:       List[str]       =		Dataset.from_list(UpperCamelCase_					)
						self.assertEqual(dset.info.features['col_1']     ,  Sequence(Value('int64'					)					)					)




					def 						__UpperCAmelCase     (  self				:	int					)  ->       Optional[int]:



						'''simple docstring'''





						_lowercase					:       Optional[Any]       =		Dataset.from_list([]					)
						self.assertEqual(len(UpperCamelCase_					)     ,  0					)
						self.assertListEqual(dset.column_names     ,  []					)





'''simple docstring'''

from __future__ import annotations

import requests







def 						__UpperCamelCase				(							_lowercase					) ->			dict:
	_lowercase					:       Optional[int]       =		f'''https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty'''
	return requests.get(_lowercase					).json()







def 						__UpperCamelCase				(							_lowercase = 10					) ->			list[dict]:
	_lowercase					:       Union[str, Any]       =		'https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty'
	_lowercase					:       Optional[Any]       =		requests.get(_lowercase					).json()[:max_stories]
	return [get_hackernews_story(_lowercase					) for story_id in story_ids]







def 						__UpperCamelCase				(							_lowercase = 10					) ->			str:
	_lowercase					:       Tuple       =		hackernews_top_stories(_lowercase					)
	return "\n".join('* [{title}]({url})'.format(**_lowercase					) for story in stories					)


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