input: Write a function to rewrite the provided code using list comprehensions. The function should read a provided loop structure and transform it into an equivalent list comprehension. The function should return the transformed code as a string.
  assert convert_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 convert_to_comprehension("""squares = []
  for x in range(10):
      squares.append(x**2)""") == "squares = [x**2 for x in range(10)]"
  assert convert_to_comprehension("""multiples_of_three = []
  for y in range(30):
      if y % 3 == 0:
          multiples_of_three.append(y)""") == "multiples_of_three = [y for y in range(30) if y % 3 == 0]"
  assert convert_to_comprehension("""empty = []
  for z in range(5):
      if False:
          empty.append(z)""") == "empty = [z for z in range(5) if False]"
  assert convert_to_comprehension("") == ""
output: def convert_to_comprehension(code):
      lines = code.strip().split('\n')
      if not lines:
          return ""
      var_name = lines[0].split('=')[0].strip()
      loop_line = lines[1].strip()
      loop_var = loop_line.split(' ')[1]
      loop_range = loop_line.split(' ')[3]
      if len(lines) == 3:
          append_line = lines[2].strip()
          if 'if' in append_line:
              condition = append_line.split('if ')[1].split(':')[0]
              return f"{var_name} = [{loop_var} for {loop_var} in {loop_range} if {condition}]"
          else:
              append_value = append_line.split('.append(')[1].split(')')[0]
              return f"{var_name} = [{append_value} for {loop_var} in {loop_range}]"
      elif len(lines) == 4:
          condition = lines[2].strip().split('if ')[1].split(':')[0]
          append_value = lines[3].strip().split('.append(')[1].split(')')[0]
          return f"{var_name} = [{append_value} for {loop_var} in {loop_range} if {condition}]"