I have a class which contains a list. I would really like it if I could easily get the number of only the top level objects/classes I am adding to that list.
class Layer:
class Neuron:
netValue = 0.
activationValue = 0.
weights = []
weightsAfterErrorSubtracted = []
incomingError = 0.
def __init__(self, numberOfWeights):
self.weights = random.random(int(numberOfWeights))
neurons = []
def __init__(self, numberOfNeurons, numberOfWeightsPerNeuron):
for neuron in range(0, numberOfNeurons):
self.neurons.append(self.Neuron(numberOfWeightsPerNeuron))
layer = Layer(40, 200)
print("The length of my list is: " + str(len(layer.neurons)))
The problem is, when I print out the length of the list after adding neurons, it includes all the weights in the neurons as well in that length, not just the number of neuron objects. Is there a way to easily just get the number of top level objects in a list, and not their children?