





"""simple docstring"""



from unittest import TestCase

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






class 		__snake_case					(		UpperCAmelCase__     ):





 """simple docstring"""


 def 					UpperCamelCase__(    self  ):



     '''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  ):



     '''simple docstring'''




     __A    :						List[Any]						 =     {'''col_1''': [3, 2, 1, 0], '''col_2''': ['''a''', '''b''', '''c''', '''d''']}
     return Dataset.from_dict(__lowercase  )

 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						Optional[Any]						 =     self._create_example_records()
     __A    :						Optional[Any]						 =     Dataset.from_list(__lowercase  )
     self.assertListEqual(dset.column_names					,						['''col_1''', '''col_2''']  )
     for i, r in enumerate(__lowercase  ):
         self.assertDictEqual(__lowercase					,						example_records[i]  )

 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						Optional[Any]						 =     self._create_example_records()
     __A    :						str						 =     Dataset.from_list(__lowercase  )
     __A    :						Optional[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  ):  # checks what happens with missing columns



     '''simple docstring'''




     __A    :						Any						 =     [{'''col_1''': 1}, {'''col_2''': '''x'''}]
     __A    :						Union[str, Any]						 =     Dataset.from_list(__lowercase  )
     self.assertDictEqual(dset[0]					,						{'''col_1''': 1}  )
     self.assertDictEqual(dset[1]					,						{'''col_1''': None}  )  # NB: first record is used for columns

 def 					UpperCamelCase__(    self  ):  # checks if the type can be inferred from the second record



     '''simple docstring'''




     __A    :						Optional[int]						 =     [{'''col_1''': []}, {'''col_1''': [1, 2]}]
     __A    :						str						 =     Dataset.from_list(__lowercase  )
     self.assertEqual(dset.info.features['''col_1''']					,						Sequence(Value('''int64'''  )  )  )







 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						List[str]						 =     Dataset.from_list([]  )
     self.assertEqual(len(__lowercase  )					,						0  )
     self.assertListEqual(dset.column_names					,						[]  )










from timeit import timeit

lowercase__				:     Union[str, Any] 		=						{
    "MALAYALAM": True,
    "String": False,
    "rotor": True,
    "level": True,
    "A": True,
    "BB": True,
    "ABC": False,
    "amanaplanacanalpanama": True,  # "a man a plan a canal panama"
}
# Ensure our test data is valid
assert all((key == key[::-1]) is value for key, value in test_data.items())


def 						lowerCamelCase__    (		_A							):







	'''simple docstring'''





	snake_case_		    =     0
	snake_case_		    =     len(_A							) - 1
	while start_i < end_i:
		if s[start_i] == s[end_i]:
			start_i += 1
			end_i -= 1
		else:
			return False
	return True


def 						lowerCamelCase__    (		_A							):







	'''simple docstring'''





	snake_case_		    =     len(_A							) // 2
	snake_case_		    =     len(_A							)

	# We need to traverse till half of the length of string
	# as we can get access of the i'th last element from
	# i'th index.
	# eg: [0,1,2,3,4,5] => 4th index can be accessed
	# with the help of 1st index (i==n-i-1)
	# where n is length of string
	return all(s[i] == s[n - i - 1] for i in range(_A							)							)


def 						lowerCamelCase__    (		_A							):







	'''simple docstring'''





	if len(_A							) <= 2:
		return True
	if s[0] == s[len(_A							) - 1]:
		return is_palindrome_recursive(s[1:-1]							)
	else:
		return False


def 						lowerCamelCase__    (		_A							):







	'''simple docstring'''





	return s == s[::-1]


def 						lowerCamelCase__    (		_A							):







	'''simple docstring'''





	snake_case_		    =     f"all({name}(key) is value for key, value in test_data.items())"
	snake_case_		    =     f"from __main__ import test_data, {name}"
	snake_case_		    =     500000
	snake_case_		    =     timeit(stmt=_A     ,	setup=_A     ,	number=_A							)
	print(f"{name:<35} finished {number:,} runs in {result:.5f} seconds"							)


if __name__ == "__main__":
		for key, value in test_data.items():
				assert is_palindrome(key) is is_palindrome_recursive(key)
				assert is_palindrome(key) is is_palindrome_slice(key)
				print(f'''{key:21} {value}''')
		print("a man a plan a canal panama")

		# finished 500,000 runs in 0.46793 seconds
		benchmark_function("is_palindrome_slice")
		# finished 500,000 runs in 0.85234 seconds
		benchmark_function("is_palindrome")
		# finished 500,000 runs in 1.32028 seconds
		benchmark_function("is_palindrome_recursive")
		# finished 500,000 runs in 2.08679 seconds
		benchmark_function("is_palindrome_traversal")
