input: Write a function to rewrite the given Python code using list comprehensions. If the input Python code is provided, return the rewritten version using list comprehensions. If no input is provided, return an empty string.
  assert rewrite_using_list_comps(
      """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 rewrite_using_list_comps("") == ""
  assert rewrite_using_list_comps(
      """squares = []
  for x in range(10):
      squares.append(x**2)"""
  ) == "squares = [x**2 for x in range(10)]"
output: def rewrite_using_list_comps(code):
      if not code:
          return ""
      lines = code.strip().split('\n')
      if len(lines) < 2:
          return ""
      var_name = lines[0].split('=')[0].strip()
      loop_line = lines[1].strip()
      if 'for' not in loop_line or 'in' not in loop_line:
          return ""
      loop_var = loop_line.split('for')[1].split('in')[0].strip()
      range_expr = loop_line.split('in')[1].strip()
      if len(lines) > 2 and 'if' in lines[2]:
          condition = lines[2].split('if')[1].strip()
          return f"{var_name} = [{loop_var} for {loop_var} in {range_expr} if {condition}]"
      else:
          return f"{var_name} = [{loop_var} for {loop_var} in {range_expr}]"