class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def removeElements(head: ListNode, key: int) -> ListNode:
    dummy = ListNode(0)
    dummy.next = head
    current = dummy
    
    while current.next:
        if current.next.val == key:
            current.next = current.next.next 
        else:
            current = current.next  
    
    return dummy.next  

def create_linked_list(arr):
    dummy = ListNode()
    current = dummy
    for val in arr:
        current.next = ListNode(val)
        current = current.next
    return dummy.next

def print_linked_list(head):
    first = True 
    while head:
        if not first:
            print(" , ", end="")  
        print(head.val, end="")
        first = False 
        head = head.next
    print()  



head = create_linked_list([1, 2, 6, 3, 4, 5, 6])
key = 6
updated_head = removeElements(head, key)
print_linked_list(updated_head)  # Output  1 , 2 , 3 , 4 , 5

head = create_linked_list([7, 8, 9, 10])
key = 9
updated_head = removeElements(head, key)
print_linked_list(updated_head)  # Output  7 , 8 , 10
