


"""simple docstring"""







from typing import Any


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       def __init__(						self		,     snake_case__						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							data
         lowerCAmelCase     :     Dict								=							None







       def __repr__(						self						):






         """simple docstring"""





         return f"""Node({self.data})"""


class       SCREAMING_SNAKE_CASE__				:
       """simple docstring"""


       def __init__(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							None

       def __iter__(						self						):






         """simple docstring"""





         lowerCAmelCase     :     List[str]								=							self.head
         while node:
           yield node.data
           lowerCAmelCase     :     Any								=							node.next

       def __len__(						self						):






         """simple docstring"""





         return sum(1 for _ in self						)

       def __repr__(						self						):






         """simple docstring"""





         return "->".join([str(snake_case__						) for item in self]						)

       def __getitem__(						self		,     snake_case__						):






         """simple docstring"""





         if not 0 <= index < len(self						):
           raise ValueError("list index out of range."						)
         for i, node in enumerate(self						):
           if i == index:
             return node
         return None

       def __setitem__(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         if not 0 <= index < len(self						):
           raise ValueError("list index out of range."						)
         lowerCAmelCase     :     Optional[int]								=							self.head
         for _ in range(snake_case__						):
           lowerCAmelCase     :     str								=							current.next
         lowerCAmelCase     :     Tuple								=							data

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         self.insert_nth(len(self						)		,     snake_case__						)

       def        lowercase__							(						self		,     snake_case__						):






         """simple docstring"""





         self.insert_nth(0		,     snake_case__						)

       def        lowercase__							(						self		,     snake_case__		,     snake_case__						):






         """simple docstring"""





         if not 0 <= index <= len(self						):
           raise IndexError("list index out of range"						)
         lowerCAmelCase     :     Dict								=							Node(snake_case__						)
         if self.head is None:
           lowerCAmelCase     :     List[Any]								=							new_node
         elif index == 0:
           lowerCAmelCase     :     int								=							self.head  # link new_node to head
           lowerCAmelCase     :     str								=							new_node
         else:
           lowerCAmelCase     :     Optional[Any]								=							self.head
           for _ in range(index - 1						):
             lowerCAmelCase     :     int								=							temp.next
           lowerCAmelCase     :     List[Any]								=							temp.next
           lowerCAmelCase     :     Optional[Any]								=							new_node

       def        lowercase__							(						self						):  # print every node data






         """simple docstring"""





         print(self						)

       def        lowercase__							(						self						):






         """simple docstring"""





         return self.delete_nth(0						)

       def        lowercase__							(						self						):  # delete from tail






         """simple docstring"""





         return self.delete_nth(len(self						) - 1						)

       def        lowercase__							(						self		,     snake_case__ = 0						):






         """simple docstring"""





         if not 0 <= index <= len(self						) - 1:  # test if index is valid
           raise IndexError("List index out of range."						)
         lowerCAmelCase     :     Tuple								=							self.head  # default first node
         if index == 0:
           lowerCAmelCase     :     Optional[int]								=							self.head.next
         else:
           lowerCAmelCase     :     Union[str, Any]								=							self.head
           for _ in range(index - 1						):
             lowerCAmelCase     :     Optional[Any]								=							temp.next
           lowerCAmelCase     :     str								=							temp.next
           lowerCAmelCase     :     str								=							temp.next.next
         return delete_node.data

       def        lowercase__							(						self						):






         """simple docstring"""





         return self.head is None







       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							None
         lowerCAmelCase     :     Tuple								=							self.head

         while current:
           # Store the current node's next node.
           lowerCAmelCase     :     Union[str, Any]								=							current.next
           # Make the current node's next point backwards
           lowerCAmelCase     :     Any								=							prev
           # Make the previous node be the current node
           lowerCAmelCase     :     Dict								=							current
           # Make the current node the next node (to progress iteration)
           lowerCAmelCase     :     Optional[int]								=							next_node
         # Return prev in order to put the head at the end
         lowerCAmelCase     :     Union[str, Any]								=							prev

def 					a__			(				):


  '''simple docstring'''







  lowerCAmelCase     :     int								=							LinkedList()
  assert linked_list.is_empty() is True
  assert str(SCREAMING_SNAKE_CASE				) == ""

  try:
    linked_list.delete_head()
    raise AssertionError  # This should not happen.
  except IndexError:
    assert True  # This should happen.

  try:
    linked_list.delete_tail()
    raise AssertionError  # This should not happen.
  except IndexError:
    assert True  # This should happen.

  for i in range(1_0				):
    assert len(SCREAMING_SNAKE_CASE				) == i
    linked_list.insert_nth(SCREAMING_SNAKE_CASE				,      i + 1				)
  assert str(SCREAMING_SNAKE_CASE				) == "->".join(str(SCREAMING_SNAKE_CASE				) for i in range(1				,      1_1				)				)

  linked_list.insert_head(0				)
  linked_list.insert_tail(1_1				)
  assert str(SCREAMING_SNAKE_CASE				) == "->".join(str(SCREAMING_SNAKE_CASE				) for i in range(0				,      1_2				)				)

  assert linked_list.delete_head() == 0
  assert linked_list.delete_nth(9				) == 1_0
  assert linked_list.delete_tail() == 1_1
  assert len(SCREAMING_SNAKE_CASE				) == 9
  assert str(SCREAMING_SNAKE_CASE				) == "->".join(str(SCREAMING_SNAKE_CASE				) for i in range(1				,      1_0				)				)

  assert all(linked_list[i] == i + 1 for i in range(0				,      9				)				) is True

  for i in range(0				,      9				):
    lowerCAmelCase     :     List[Any]								=							-i
  assert all(linked_list[i] == -i for i in range(0				,      9				)				) is True

  linked_list.reverse()
  assert str(SCREAMING_SNAKE_CASE				) == "->".join(str(SCREAMING_SNAKE_CASE				) for i in range(-8				,      1				)				)
def 					a__			(				):


  '''simple docstring'''







  lowerCAmelCase     :     List[Any]								=							[
      -9,
      1_0_0,
      Node(7_7_3_4_5_1_1_2				),
      "dlrow olleH",
      7,
      5_5_5_5,
      0,
      -192.55_555,
      "Hello, world!",
      77.9,
      Node(1_0				),
      None,
      None,
      12.20,
  ]
  lowerCAmelCase     :     Tuple								=							LinkedList()

  for i in test_input:
    linked_list.insert_tail(SCREAMING_SNAKE_CASE				)

  # Check if it's empty or not
  assert linked_list.is_empty() is False
  assert (
      str(SCREAMING_SNAKE_CASE				) == "-9->100->Node(77345112)->dlrow olleH->7->5555->0->"
      "-192.55555->Hello, world!->77.9->Node(10)->None->None->12.2"
  )

  # Delete the head
  lowerCAmelCase     :     Tuple								=							linked_list.delete_head()
  assert result == -9
  assert (
      str(SCREAMING_SNAKE_CASE				) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
      "Hello, world!->77.9->Node(10)->None->None->12.2"
  )

  # Delete the tail
  lowerCAmelCase     :     List[Any]								=							linked_list.delete_tail()
  assert result == 12.2
  assert (
      str(SCREAMING_SNAKE_CASE				) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
      "Hello, world!->77.9->Node(10)->None->None"
  )

  # Delete a node in specific location in linked list
  lowerCAmelCase     :     Union[str, Any]								=							linked_list.delete_nth(1_0				)
  assert result is None
  assert (
      str(SCREAMING_SNAKE_CASE				) == "100->Node(77345112)->dlrow olleH->7->5555->0->-192.55555->"
      "Hello, world!->77.9->Node(10)->None"
  )

  # Add a Node instance to its head
  linked_list.insert_head(Node("Hello again, world!"				)				)
  assert (
      str(SCREAMING_SNAKE_CASE				)
      == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
      "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None"
  )

  # Add None to its tail
  linked_list.insert_tail(SCREAMING_SNAKE_CASE				)
  assert (
      str(SCREAMING_SNAKE_CASE				)
      == "Node(Hello again, world!)->100->Node(77345112)->dlrow olleH->"
      "7->5555->0->-192.55555->Hello, world!->77.9->Node(10)->None->None"
  )

  # Reverse the linked list
  linked_list.reverse()
  assert (
      str(SCREAMING_SNAKE_CASE				)
      == "None->None->Node(10)->77.9->Hello, world!->-192.55555->0->5555->"
      "7->dlrow olleH->Node(77345112)->100->Node(Hello again, world!)"
  )
def 					a__			(				):


  '''simple docstring'''







  from doctest import testmod

  testmod()

  lowerCAmelCase     :     Dict								=							LinkedList()
  linked_list.insert_head(input("Inserting 1st at head "				).strip()				)
  linked_list.insert_head(input("Inserting 2nd at head "				).strip()				)
  print("\nPrint list:"				)
  linked_list.print_list()
  linked_list.insert_tail(input("\nInserting 1st at tail "				).strip()				)
  linked_list.insert_tail(input("Inserting 2nd at tail "				).strip()				)
  print("\nPrint list:"				)
  linked_list.print_list()
  print("\nDelete head"				)
  linked_list.delete_head()
  print("Delete tail"				)
  linked_list.delete_tail()
  print("\nPrint list:"				)
  linked_list.print_list()
  print("\nReverse linked list"				)
  linked_list.reverse()
  print("\nPrint list:"				)
  linked_list.print_list()
  print("\nString representation of linked list:"				)
  print(SCREAMING_SNAKE_CASE				)
  print("\nReading/changing Node data using indexing:"				)
  print(f"""Element at Position 1: {linked_list[1]}"""				)
  lowerCAmelCase     :     List[Any]								=							input("Enter New Value: "				).strip()
  print("New list:"				)
  print(SCREAMING_SNAKE_CASE				)
  print(f"""length of linked_list is : {len(SCREAMING_SNAKE_CASE				)}"""				)


if __name__ == "__main__":
     main()









"""simple docstring"""







import unittest

from transformers import BigBirdTokenizer, BigBirdTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, require_torch, slow
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin


lowerCAmelCase__      				=   '''▁'''

lowerCAmelCase__      				=   get_tests_dir('''fixtures/test_sentencepiece.model''')


@require_sentencepiece
@require_tokenizers
class       SCREAMING_SNAKE_CASE__				(		lowercase   ,    unittest.TestCase				):
       """simple docstring"""


       a  :				str   =BigBirdTokenizer
       a  :				Union[str, Any]   =BigBirdTokenizerFast
       a  :				Tuple   =True
       a  :				Any   =True

       def        lowercase__							(						self						):






         """simple docstring"""





         super().setUp()

         lowerCAmelCase     :     str								=							self.tokenizer_class(snake_case__		,     keep_accents=snake_case__						)
         tokenizer.save_pretrained(self.tmpdirname						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     str								=							"<s>"
         lowerCAmelCase     :     Optional[int]								=							1

         self.assertEqual(self.get_tokenizer()._convert_token_to_id(snake_case__						)		,     snake_case__						)
         self.assertEqual(self.get_tokenizer()._convert_id_to_token(snake_case__						)		,     snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Dict								=							list(self.get_tokenizer().get_vocab().keys()						)

         self.assertEqual(vocab_keys[0]		,     "<unk>"						)
         self.assertEqual(vocab_keys[1]		,     "<s>"						)
         self.assertEqual(vocab_keys[-1]		,     "[MASK]"						)
         self.assertEqual(len(snake_case__						)		,     1_004						)

       def        lowercase__							(						self						):






         """simple docstring"""





         self.assertEqual(self.get_tokenizer().vocab_size		,     1_000						)

       def        lowercase__							(						self						):






         """simple docstring"""





         if not self.test_rust_tokenizer:
           return

         lowerCAmelCase     :     Tuple								=							self.get_tokenizer()
         lowerCAmelCase     :     Optional[int]								=							self.get_rust_tokenizer()

         lowerCAmelCase     :     Tuple								=							"I was born in 92000, and this is falsé."

         lowerCAmelCase     :     Optional[int]								=							tokenizer.tokenize(snake_case__						)
         lowerCAmelCase     :     int								=							rust_tokenizer.tokenize(snake_case__						)
         self.assertListEqual(snake_case__		,     snake_case__						)

         lowerCAmelCase     :     Tuple								=							tokenizer.encode(snake_case__		,     add_special_tokens=snake_case__						)
         lowerCAmelCase     :     int								=							rust_tokenizer.encode(snake_case__		,     add_special_tokens=snake_case__						)
         self.assertListEqual(snake_case__		,     snake_case__						)

         lowerCAmelCase     :     List[Any]								=							self.get_rust_tokenizer()
         lowerCAmelCase     :     Tuple								=							tokenizer.encode(snake_case__						)
         lowerCAmelCase     :     List[Any]								=							rust_tokenizer.encode(snake_case__						)
         self.assertListEqual(snake_case__		,     snake_case__						)

       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							BigBirdTokenizer(snake_case__		,     keep_accents=snake_case__						)

         lowerCAmelCase     :     Union[str, Any]								=							tokenizer.tokenize("This is a test"						)
         self.assertListEqual(snake_case__		,     ["▁This", "▁is", "▁a", "▁t", "est"]						)

         self.assertListEqual(
             tokenizer.convert_tokens_to_ids(snake_case__						)		,     [285, 46, 10, 170, 382]		,     )

         lowerCAmelCase     :     Any								=							tokenizer.tokenize("I was born in 92000, and this is falsé."						)
         self.assertListEqual(
             snake_case__		,     [
                 SPIECE_UNDERLINE + "I",
                 SPIECE_UNDERLINE + "was",
                 SPIECE_UNDERLINE + "b",
                 "or",
                 "n",
                 SPIECE_UNDERLINE + "in",
                 SPIECE_UNDERLINE + "",
                 "9",
                 "2",
                 "0",
                 "0",
                 "0",
                 ",",
                 SPIECE_UNDERLINE + "and",
                 SPIECE_UNDERLINE + "this",
                 SPIECE_UNDERLINE + "is",
                 SPIECE_UNDERLINE + "f",
                 "al",
                 "s",
                 "é",
                 ".",
             ]		,     )
         lowerCAmelCase     :     str								=							tokenizer.convert_tokens_to_ids(snake_case__						)
         self.assertListEqual(
             snake_case__		,     [8, 21, 84, 55, 24, 19, 7, 0, 602, 347, 347, 347, 3, 12, 66, 46, 72, 80, 6, 0, 4]		,     )

         lowerCAmelCase     :     List[str]								=							tokenizer.convert_ids_to_tokens(snake_case__						)
         self.assertListEqual(
             snake_case__		,     [
                 SPIECE_UNDERLINE + "I",
                 SPIECE_UNDERLINE + "was",
                 SPIECE_UNDERLINE + "b",
                 "or",
                 "n",
                 SPIECE_UNDERLINE + "in",
                 SPIECE_UNDERLINE + "",
                 "<unk>",
                 "2",
                 "0",
                 "0",
                 "0",
                 ",",
                 SPIECE_UNDERLINE + "and",
                 SPIECE_UNDERLINE + "this",
                 SPIECE_UNDERLINE + "is",
                 SPIECE_UNDERLINE + "f",
                 "al",
                 "s",
                 "<unk>",
                 ".",
             ]		,     )

       @cached_property
       def        lowercase__							(						self						):






         """simple docstring"""





         return BigBirdTokenizer.from_pretrained("google/bigbird-roberta-base"						)

       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     List[Any]								=							"Hello World!"
         lowerCAmelCase     :     Any								=							[65, 18_536, 2_260, 101, 66]

         self.assertListEqual(snake_case__		,     self.big_tokenizer.encode(snake_case__						)						)

       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Union[str, Any]								=							(
             "This is a very long text with a lot of weird characters, such as: . , ~ ? ( ) \" [ ] ! : - . Also we will"
             " add words that should not exsist and be tokenized to <unk>, such as saoneuhaoesuth"
         )
         # fmt: off
         lowerCAmelCase     :     List[str]								=							[65, 871, 419, 358, 946, 991, 2_521, 452, 358, 1_357, 387, 7_751, 3_536, 112, 985, 456, 126, 865, 938, 5_400, 5_734, 458, 1_368, 467, 786, 2_462, 5_246, 1_159, 633, 865, 4_519, 457, 582, 852, 2_557, 427, 916, 508, 405, 34_324, 497, 391, 408, 11_342, 1_244, 385, 100, 938, 985, 456, 574, 362, 12_597, 3_200, 3_129, 1_172, 66]  # noqa: E231
         # fmt: on
         self.assertListEqual(snake_case__		,     self.big_tokenizer.encode(snake_case__						)						)

       @require_torch
       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         import torch

         from transformers import BigBirdConfig, BigBirdModel

         # Build sequence
         lowerCAmelCase     :     Dict								=							list(self.big_tokenizer.get_vocab().keys()						)[:10]
         lowerCAmelCase     :     int								=							" ".join(snake_case__						)
         lowerCAmelCase     :     Dict								=							self.big_tokenizer.encode_plus(snake_case__		,     return_tensors="pt"		,     return_token_type_ids=snake_case__						)
         lowerCAmelCase     :     Any								=							self.big_tokenizer.batch_encode_plus(
             [sequence + " " + sequence]		,     return_tensors="pt"		,     return_token_type_ids=snake_case__						)

         lowerCAmelCase     :     str								=							BigBirdConfig(attention_type="original_full"						)
         lowerCAmelCase     :     Any								=							BigBirdModel(snake_case__						)

         assert model.get_input_embeddings().weight.shape[0] >= self.big_tokenizer.vocab_size

         with torch.no_grad():
           model(**snake_case__						)
           model(**snake_case__						)

       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     List[str]								=							BigBirdTokenizer.from_pretrained("google/bigbird-roberta-base"						)
         lowerCAmelCase     :     Union[str, Any]								=							tokenizer.decode(tokenizer("Paris is the [MASK]."						).input_ids						)

         self.assertTrue(decoded_text == "[CLS] Paris is the[MASK].[SEP]"						)







       @slow
       def        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Any								=							{"input_ids": [[65, 39_286, 458, 36_335, 2_001, 456, 13_073, 13_266, 455, 113, 7_746, 1_741, 11_157, 391, 13_073, 13_266, 455, 113, 3_967, 35_412, 113, 4_936, 109, 3_870, 2_377, 113, 30_084, 45_720, 458, 134, 17_496, 112, 503, 11_672, 113, 118, 112, 5_665, 13_347, 38_687, 112, 1_496, 31_389, 112, 3_268, 47_264, 134, 962, 112, 16_377, 8_035, 23_130, 430, 12_169, 15_518, 28_592, 458, 146, 41_697, 109, 391, 12_169, 15_518, 16_689, 458, 146, 41_358, 109, 452, 726, 4_034, 111, 763, 35_412, 5_082, 388, 1_903, 111, 9_051, 391, 2_870, 48_918, 1_900, 1_123, 550, 998, 112, 9_586, 15_985, 455, 391, 410, 22_955, 37_636, 114, 66], [65, 448, 17_496, 419, 3_663, 385, 763, 113, 27_533, 2_870, 3_283, 13_043, 1_639, 24_713, 523, 656, 24_013, 18_550, 2_521, 517, 27_014, 21_244, 420, 1_212, 1_465, 391, 927, 4_833, 388, 578, 11_786, 114, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [65, 484, 2_169, 7_687, 21_932, 18_146, 726, 363, 17_032, 3_391, 114, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
         # fmt: on

         self.tokenizer_integration_test_util(
             expected_encoding=snake_case__		,     model_name="google/bigbird-roberta-base"		,     revision="215c99f1600e06f83acce68422f2035b2b5c3510"		,     )





