title: Prime numbers and tuples
body: <p>I am beginner in python and I am working on one problem which I am not able to solve. </p>
  
  <p><strong><em>What I am supposed to do:</em></strong> create a list of tuples with prime numbers, the range is two numbers(which are also prime numbers) and the tuples in that list are supposed to contain only 2 prime numbers p and p+2</p>
  
  <p><strong><em>For example</em></strong>: given range (11, 31) returned list = [(11, 13), (17, 19), (29, 31)] </p>
  
  <p>This is my code </p>
  
  <pre><code>def twin_primes(a: int, b:int) -&gt; List[Tuple[int, int]]:
  
      list_primes = []
      list_final = []
      for val in range (a, b+1):
          if val &gt; 1 :
              for n in range(2, val):
                  if (val % n) == 0:
                      break
              else:
                  list_primes.append(val)
      for val in list_primes:
          print(val)
          list_final.append((list_primes[val], list_primes[val + 2]))
      return list_final
  
  print(twin_primes(11,31))
  </code></pre>
  
  <p>in the first for cycle I determine which numbers in that range are prime and append them to <code>list_primes</code></p>
  
  <p>in the second for cycle I tried to take the prime numbers from <code>list_primes</code> and append them as tuples into <code>list_final</code></p>
  
  <p>it tells me this : </p>
  
  <blockquote>
    <p>list_final.append((list_primes[val], list_primes[val + 2]))<br>
    IndexError: list index out of range* </p>
  </blockquote>
  
  <p>could someone please help me with this? I think I understand that error but I don't know how to fix the code so it just takes the <code>p</code>, <code>p+2</code> into one tuple and then it would take another pair and so on... also it has to ignore 23 even though it is prime number. </p>