0

I am trying to assign values to a list at ith position.

coords = [] 

lat = 37.312312
long = -118.31231

coords[0] = lat
coords[1] = long

IndexError                                Traceback (most recent call last)
/var/folders/d0/gnksqzwn2fn46fjgrkp6045c0000gn/T/ipykernel_56868/3062929082.py in <module>
      4 long = -118.31231
      5 
----> 6 coords[0] = lat
      7 coords[1] = long

IndexError: list assignment index out of range
kms
  • 1,810
  • 1
  • 41
  • 92
  • Does this answer your question? [Why does this iterative list-growing code give IndexError: list assignment index out of range?](https://stackoverflow.com/questions/5653533/why-does-this-iterative-list-growing-code-give-indexerror-list-assignment-index) – Nick May 19 '22 at 23:05

1 Answers1

0

I mean, you could do this if you REALLY don’t want to use append:

coords = [0,0] 

lat = 37.312312
long = -118.31231

coords[0] = lat
coords[1] = long
Pwuurple
  • 352
  • 2
  • 11