1

I need to create 189 instances of class.Name that contains string. How can I do that?

Following code does not work.

def naming_of_sequence_neurons():
    letters_list = ["a", "b", "c", "d", "e", "f", "g",
                    "h", "i", "k", "l", "m", "n", "p",
                    "q", "r", "s", "t", "v", "w", "y"]

    input_neuron_web = []

    def naming_cycle(number):

        for j in range(0, 21):
            input_neuron_web[j][number] = Neuron.name = (letters_list[j] + str(number))

    for i in range(0, 9):
        naming_cycle(i)

    return input_neuron_web

inputed = naming_of_sequence_neurons()

for a in range(0, 21):
    for b in range(0, 9):
        print(inputed[a][b].name)
1
  • 1
    Could you add the definition of Neuron? Commented Feb 16, 2018 at 7:14

1 Answer 1

1

The problem seems to be that you're assigning values to indices that don't exist yet. That won't work for a Python list.

Assuming Neuron is a reasonably well-behaved object, this is likely to work:

def naming_of_sequence_neurons():
    letters_list = ["a", "b", "c", "d", "e", "f", "g",
                    "h", "i", "k", "l", "m", "n", "p",
                    "q", "r", "s", "t", "v", "w", "y"]
    input_neuron_web = []
    for number in range(0, 9):
        new_list = []
        for j in range(0,21):
            new_neuron = Neuron()
            new_neuron.name = letters_list[j] + str(number)
            new_list.append(new_neuron)
        input_neuron_web.append(new_list)
    return input_neuron_web
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.