Search code examples
pythonpython-3.xlistenumerate

Enumerate - Python loop


I have two lists with just one element as follows(each of these two lists always contains only one element):

Vnew = [600]
Newoints2 = [(2447,3480)]

I'm trying to bring both of them together using the following code sample:

for i, key in enumerate(Vnew2):
  pos3[key] = newpoints2[i]

But this returns an error as IndexError: list assignment index out of range

I actually did this one for other lists which have more than one element. It worked fine and got the output as {0:(1245,674),1:(2457,895),...}

Can someone find the mistake here?


Solution

  • It looks like you are trying to concatenate the lists into a new list. You don't always need to enumerate through the list.

    You will be able to do this by Vnew + Newoints2