<jupyter_start><jupyter_text>Title : List partition하기Chapter : Linked ListLink :ChapterLink :문제 : 주어진 List를 x보다 작은수를 먼저, x보다 큰수를 나중에 나오도록 partition하여라. 이때 순서가 list안 node의 순서가 바뀌면 안된다input : 1→3→7→5→3→6→3, x=5 \답 :  1→3→3→7→5→6<jupyter_code>from typing import List

class ListNode:
  def __init__(self, x):
    self.val = x
    self.next = None

def createList(in_list:List[int]) -> ListNode:
  if len(in_list) == 0:
    raise RuntimeError("in_list must have data")        
  head_node = ListNode(in_list[0])
  last_node = head_node
  for idx in range(1,len(in_list)):
    node = ListNode(in_list[idx])
    last_node.next = node
    last_node = node
  return head_node

def printNodes(node:ListNode):
  crnt_node = node
  while crnt_node is not None:
    print(crnt_node.val, end=' ')
    crnt_node = crnt_node.next
  print()

class Partitioner:
  def partition(self, head: ListNode, x: int) -> ListNode:
    dummy_a = ListNode(-1)
    dummy_b = ListNode(-1)
    
    node_a = dummy_a
    node_b = dummy_b
    
    crnt_node = head
    while crnt_node:
      val = crnt_node.val
      if x <= val:
        node_b.next = crnt_node
        node_b = node_b.next
        crnt_node = crnt_node.next
      else:
        node_a.next = crnt_node
        node_a = node_a.next
        crnt_node = crnt_node.next
        
    node_b.next = None
    node_a.next = dummy_b.next
    
    return dummy_a.next

partitioner = Partitioner()
head = createList([1,3,7,5,3,6])
partition_head = partitioner.partition(head,5)
printNodes(partition_head)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10397946084724005, 'fraction_numerical': 0.01668806161745828, 'mean_word_length': 3.0598958333333335, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '444199', 'license': 'MIT', 'n_tokens_mistral': 634, 'n_tokens_neox': 658, 'n_words': 133, 'path': 'linkedList/partitionOrder.ipynb', 'repo_name': 'NoCodeProgram/CodingTest', 'size': '1558'}