title: Need to retrieve a dynamic list element by its index
body: <p>I'm working with a modem, so everything that gets sent for or by the modem gets appended to my list. </p>
  
  <p>The thing I must retrieve is already inside this list, but if I try to print it by the index, it returns me error saying that the list doesn't have that element.</p>
  
  <p>I get why the error occur, since my list begins empty, and ends up with 7 elements.</p>
  
  <p>I tried to create a new assist variable, but I'm having no progress up until now.</p>
  
  <p>The code part:</p>
  
  <pre><code>if (e == 'SBDRING'):  #change to format code
  
          print ('Ring Alert recebido')
          lido = True
          ser.write(str.encode('AT+SBDIX\r'))
          time.sleep(5)
          ser.write(str.encode('AT+SBDRT\r'))
          time.sleep(2)
          lista = []
          assistvar = 0
          while len(lista) &lt; 10:
              u = ser.readline()
              i = u.rstrip()
              o = i.decode('utf-8')
              if len(o) &gt; 1 :
                  lista.append(o)
                  assistvar = assistvar + 1
                  print(lista)
                  print('Lista size = ', len(lista))
                  print('Assistvar = ', assistvar)
  </code></pre>
  
  <p>I know as a matter of fact that my message will be the second last element on my list. That's what I need to assign to a new variable, so I can program my popup with the message in question.</p>
  
  <p>The output for the above code is:</p>
  
  <pre><code>Ring Alert recebido
  ['AT+SBDIX']
  Lista size =  1
  Assistvar =  1
  ['AT+SBDIX', '+SBDIX: 0, 196, 1, 126, 11, 5']
  Lista size =  2
  Assistvar =  2
  ['AT+SBDIX', '+SBDIX: 0, 196, 1, 126, 11, 5', 'OK']
  Lista size =  3
  Assistvar =  3
  ['AT+SBDIX', '+SBDIX: 0, 196, 1, 126, 11, 5', 'OK', 'AT+SBDRT']
  Lista size =  4
  Assistvar =  4
  ['AT+SBDIX', '+SBDIX: 0, 196, 1, 126, 11, 5', 'OK', 'AT+SBDRT', '+SBDRT:']
  Lista size =  5
  Assistvar =  5
  ['AT+SBDIX', '+SBDIX: 0, 196, 1, 126, 11, 5', 'OK', 'AT+SBDRT', '+SBDRT:', 'jupytertest']
  Lista size =  6
  Assistvar =  6
  ['AT+SBDIX', '+SBDIX: 0, 196, 1, 126, 11, 5', 'OK', 'AT+SBDRT', '+SBDRT:', 'jupytertest', 'OK']
  Lista size =  7
  Assistvar =  7
  </code></pre>
  
  <p>Which 'jupytertest' is what I must retrieve.</p>
  
  <p>Changing the code to:</p>
  
  <pre><code>print(lista)
                      if assistvar &gt; 6:
                          print(lista[5])
                          break
  </code></pre>
  
  <p>I get this output:</p>
  
  <pre><code>Ring Alert recebido
  ['AT+SBDIX']
  ['AT+SBDIX', '+SBDIX: 18, 198, 2, 0, 0, 0']
  ['AT+SBDIX', '+SBDIX: 18, 198, 2, 0, 0, 0', 'OK']
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>@edit:
  Found a way with your help hehe. Using my assistvar, I was putting my looping to read the fifth element inside the looping to add any message with lenght greater than zero to my list. I took it out, and now I'm able to print only my message!</p>
  
  <p>The edit on my code:</p>
  
  <pre><code>                if len(o) &gt; 1 :
                      lista.append(o)
                      assistvar = assistvar + 1
                      print(lista)
                  if assistvar == 7:
                      print(lista[5])
                      break
  </code></pre>