input: Write a function to rewrite the given Python code using list comprehension. The input code attempts to find all even numbers between 1 and 20 using a for loop. The function should convert this into a single line of list comprehension.
  assert transform_to_comprehension('''even_numbers = []
  for i in range(1,21):
      if i % 2 == 0:
          even_numbers.append(i)''') == 'even_numbers = [i for i in range(1, 21) if i % 2 == 0]'
  assert transform_to_comprehension('''squares = []
  for x in range(10):
      squares.append(x**2)''') == 'squares = [x**2 for x in range(10)]'
  assert transform_to_comprehension('''filtered_list = []
  for item in range(20):
      if item > 10:
          filtered_list.append(item)''') == 'filtered_list = [item for item in range(20) if item > 10]'
output: def transform_to_comprehension(code):
      lines = code.strip().split('\n')
      var_name = lines[0].split('=')[0].strip()
      loop_var = lines[1].split(' ')[1]
      range_expr = lines[1].split('in ')[1].strip()
      if_cond = lines[2].split('if ')[1].strip() if 'if' in lines[2] else None
      append_expr = lines[2].split('.append(')[1].strip(')') if if_cond else lines[2].split('.append(')[1].strip(')')
      return f"{var_name} = [{append_expr} for {loop_var} in {range_expr}{' if ' + if_cond if if_cond else ''}]"