Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to give variables to a list?
#3
(Nov-17-2017, 05:58 AM)heiner55 Wrote:
str = "000\n111\n222\n333\n444\n555\n"
lis = str.splitlines()


print(lis[3])
print(lis[5])
Output:
333 555

>>> print(lis[3])
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
print(lis[3])
IndexError: list index out of range

>>> for div in soup.find_all('div', class_='results-link'):
str = ('https://globenewswire.com' + div.h1.a['href'])
lis = str.splitlines()
print(lis[7])


Traceback (most recent call last):
File "<pyshell#16>", line 4, in <module>
print(lis[7])
IndexError: list index out of range


tried that and got error both times. That is the error it sends back to me. I tried two different list values. Any idea why it may not be working? I'm on Python 3.6.3 if that makes any difference.
Reply


Messages In This Thread
How to give variables to a list? - by HiImNew - Nov-17-2017, 05:31 AM
RE: How to give variables to a list? - by heiner55 - Nov-17-2017, 05:58 AM
RE: How to give variables to a list? - by HiImNew - Nov-17-2017, 07:03 AM
RE: How to give variables to a list? - by heiner55 - Nov-17-2017, 07:32 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020