input: Write a function to convert a given loop into a list comprehension. The function should take a loop that appends elements to a list based on a condition and return the corresponding list comprehension. The function should handle loops that iterate over a range of numbers and apply a conditional check.
  
  assert loop_to_comprehension("""
  even_numbers = []
  for i in range(1,21):
      if i % 2 == 0:
          even_numbers.append(i)
  """) == '[i for i in range(1, 21) if i % 2 == 0]'
  
  assert loop_to_comprehension("""
  squares = []
  for j in range(1,11):
      squares.append(j * j)
  """) == '[j * j for j in range(1, 11)]'
  
  assert loop_to_comprehension("""
  multiples_of_three = []
  for k in range(1,31):
      if k % 3 == 0:
          multiples_of_three.append(k)
  """) == '[k for k in range(1, 31) if k % 3 == 0]'
  
  assert loop_to_comprehension("""
  empty_list = []
  for x in range(5):
      empty_list.append(x)
  """) == '[x for x in range(5)]'
  
  assert loop_to_comprehension("""
  single_item = []
  for item in ['a']:
      single_item.append(item)
  """) == "['a']"
output: def loop_to_comprehension(loop_code):
      import re
      loop_code = loop_code.strip()
      match = re.search(r'for (\w+) in (.*?):', loop_code)
      if not match:
          return None
      var = match.group(1)
      iterable = match.group(2)
      if 'if' in loop_code:
          condition_match = re.search(r'if (.*?):', loop_code)
          condition = condition_match.group(1)
          return f'[{var} for {var} in {iterable} if {condition}]'
      else:
          return f'[{var} for {var} in {iterable}]'