





"""simple docstring"""





import itertools
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa

import datasets
from datasets.table import table_cast


_lowerCamelCase       =	datasets.utils.logging.get_logger(__name__)





@dataclass
class 			snake_case		(   datasets.BuilderConfig   ):
      lowerCamelCase__						= None







class 			snake_case		(   datasets.ArrowBasedBuilder   ):
      lowerCamelCase__						= ArrowConfig

      def 						SCREAMING_SNAKE_CASE_			(			self   :Union[str, Any]						):
       return datasets.DatasetInfo(features=self.config.features						)

      def 						SCREAMING_SNAKE_CASE_			(			self   :Any						,							_lowerCamelCase   :Union[str, Any]						):
       if not self.config.data_files:
        raise ValueError(f'''At least one data file must be specified, but got data_files={self.config.data_files}'''						)
       __SCREAMING_SNAKE_CASE :			str												=       dl_manager.download_and_extract(self.config.data_files						)
       if isinstance(_lowerCamelCase						,							(str, list, tuple)						):
        __SCREAMING_SNAKE_CASE :			List[Any]												=       data_files
        if isinstance(_lowerCamelCase						,							_lowerCamelCase						):
         __SCREAMING_SNAKE_CASE :			List[str]												=       [files]
        # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
        __SCREAMING_SNAKE_CASE :			Dict												=       [dl_manager.iter_files(_lowerCamelCase						) for file in files]
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN						,							gen_kwargs={'''files''': files}						)]
       __SCREAMING_SNAKE_CASE :			str												=       []
       for split_name, files in data_files.items():
        if isinstance(_lowerCamelCase						,							_lowerCamelCase						):
         __SCREAMING_SNAKE_CASE :			List[str]												=       [files]
        # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
        __SCREAMING_SNAKE_CASE :			str												=       [dl_manager.iter_files(_lowerCamelCase						) for file in files]
        # Infer features is they are stoed in the arrow schema
        if self.info.features is None:
         for file in itertools.chain.from_iterable(_lowerCamelCase						):
          with open(_lowerCamelCase						,							'''rb'''						) as f:
           __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       datasets.Features.from_arrow_schema(pa.ipc.open_stream(_lowerCamelCase						).schema						)
          break
        splits.append(datasets.SplitGenerator(name=_lowerCamelCase						,							gen_kwargs={'''files''': files}						)						)
       return splits

      def 						SCREAMING_SNAKE_CASE_			(			self   :int						,							_lowerCamelCase   :pa.Table						):
       if self.info.features is not None:
        # more expensive cast to support nested features with keys in a different order
        # allows str <-> int/float or str to Audio for example
        __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       table_cast(_lowerCamelCase						,							self.info.features.arrow_schema						)
       return pa_table



      def 						SCREAMING_SNAKE_CASE_			(			self   :Union[str, Any]						,							_lowerCamelCase   :int						):
       for file_idx, file in enumerate(itertools.chain.from_iterable(_lowerCamelCase						)						):
        with open(_lowerCamelCase						,							'''rb'''						) as f:
         try:
          for batch_idx, record_batch in enumerate(pa.ipc.open_stream(_lowerCamelCase						)						):
           __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       pa.Table.from_batches([record_batch]						)
           # Uncomment for debugging (will print the Arrow table size and elements)
           # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
           # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
           yield f'''{file_idx}_{batch_idx}''', self._cast_table(_lowerCamelCase						)
         except ValueError as e:
          logger.error(f'''Failed to read file \'{file}\' with error {type(_lowerCamelCase						)}: {e}'''						)
          raise






"""simple docstring"""
def 				lowerCAmelCase_(      lowercase_   :							str  ,      lowercase_   :							str							)		->				int:
				# The longer word should come first
				if len(lowercase_							) < len(lowercase_							):
								return levenshtein_distance(lowercase_  ,      lowercase_							)

				if len(lowercase_							) == 0:
								return len(lowercase_							)

				_lowerCamelCase					     = list(range(len(lowercase_							) + 1							)							)

				for i, ca in enumerate(lowercase_							):
								_lowerCamelCase					     = [i + 1]

								for j, ca in enumerate(lowercase_							):
												# Calculate insertions, deletions and substitutions
												_lowerCamelCase					     = previous_row[j + 1] + 1
												_lowerCamelCase					     = current_row[j] + 1
												_lowerCamelCase					     = previous_row[j] + (ca != ca)

												# Get the minimum to append to the current row
												current_row.append(min(lowercase_  ,      lowercase_  ,      lowercase_							)							)

								# Store the previous row
								_lowerCamelCase					     = current_row

				# Returns the last element (distance)
				return previous_row[-1]


if __name__ == "__main__":
			__SCREAMING_SNAKE_CASE     :  int										=					input('''Enter the first word:\n''').strip()
			__SCREAMING_SNAKE_CASE     :  Optional[Any]										=					input('''Enter the second word:\n''').strip()

			__SCREAMING_SNAKE_CASE     :  Optional[Any]										=					levenshtein_distance(first_word, second_word)
			print(F"""Levenshtein distance between {first_word} and {second_word} is {result}""")
