Skip to content
Advertisement

Python, adding a different characteristic to each element of a list

i am currently working on a producion optimization tool. There are Jobs who needs to be produced on machines.

I want to add a workspeed for the machines so they can finish the jobs in a different speed depending on the machine it is processed on.

This is the class and list i am using for the machines:

JavaScript

i want to add a different float(for example 0.5 , 1.0 , 1.5) to each object in the list “all_machines”

Help would be very much appreciated!

Thanks in advance!

Advertisement

Answer

If you want workload to always have an initial value of 0 just define it in the class and remove the parameter from the __init__

JavaScript

If you want to keep __init__ with those two parameters you can use default value (notice the order of the parameters is reversed)

JavaScript

For both options

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