Skip to content
Advertisement

Subtracting 2 lists in Python

Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like

JavaScript

Should I use tuples?

If none of them defines these operands on these types, can I define it instead?

If not, should I create a new vector3 class?

Advertisement

Answer

If this is something you end up doing frequently, and with different operations, you should probably create a class to handle cases like this, or better use some library like Numpy.

Otherwise, look for list comprehensions used with the zip builtin function:

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