Skip to content
Advertisement

Append an input to a method parameter list

I’m using a generic local crud so i can implement the same method for every single list, but when trying to add a value to a list it doesn’t update the root list but the parameter one does, any help?

JavaScript

If i print the parameter “lista” when appends the new value it returns the list with the new value, but when i enter the list option, the list shows empty.

Advertisement

Answer

You create a new empty list on every iteration of while True:

JavaScript

will always give [1], not [1], [1,1], ….

Don’t run the above, it will just busy loop until it explodes.

To solve your issue, you need to declare the list once, outside your interactive loop.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement