Python Forum
List index out of range error while accessing 2 lists in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List index out of range error while accessing 2 lists in python
#1
I have 2 Lists in my code.
data list is having len = 11
new_list is having len = 23

I have to search if a string from data list exists in new_list.. I can see that my target_data gets filled with data,but when i go to print it i get an error..

here is my code:

        print len(new_list)
		print len(data)
		
		for i in range(len(new_list)):
			parts = (new_list[i].split('|'))
			#print parts
			if (int(parts[8]) >= 1 or int(parts[9])  >= 1 or int(parts[11])  >= 1 ):
				variable = parts[1]
				variable = variable.strip()
				variable = variable + "']"
				#print variable
				for d in data:
					if variable in d:
						target_data.append(d)	
						print "ok"
					else:
						NODATA = 1
			else:
				NODATA = 1
		print target_data
Error:
23 11 ok ok ok ok ok ok ok ok ok ok ok list index out of range
How do i take care of this list out of range error?
Reply


Messages In This Thread
List index out of range error while accessing 2 lists in python - by K11 - Sep-29-2020, 05:07 AM
RE: List index out of range - by buran - Sep-29-2020, 05:08 AM
RE: List index out of range - by K11 - Sep-29-2020, 05:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: list index out of range Laplace12 1 103 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  python error: bad character range \|-t at position 12 faustineaiden 0 174 May-28-2021, 09:38 AM
Last Post: faustineaiden
  How to resolve Index Error in my code? codify110 6 366 May-22-2021, 11:04 AM
Last Post: supuflounder
  List of lists - merge sublists with common elements medatib531 1 351 May-09-2021, 07:49 AM
Last Post: Gribouillis
  Sort List of Lists by Column Nju 1 369 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  IndexError: list index out of range brunolelli 11 925 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  index of range, but data prints out mrc06405j 1 345 Mar-25-2021, 07:20 PM
Last Post: buran
  Changing Index of 2 List in python giddyhead 0 319 Mar-05-2021, 05:45 PM
Last Post: giddyhead
  IndexError: list index out of range ramu4651 2 543 Jan-24-2021, 01:45 PM
Last Post: buran
  string index out of range jade_kim 4 480 Jan-13-2021, 05:41 AM
Last Post: jade_kim

Forum Jump:

User Panel Messages

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