Ask coding questions

← Back to all posts
Problem with list indexing?
kaedyngrice (1)

Reposting because I made a mistake on my first post.
I'm making this word generator to help me make words for a conlang that I'm making. The program starts by creating the structure of the word using lists of empty strings, and then sounds are added. Here is the short version of the problem I am running into


word_struc = [["", ""], [""], ["", ""]]
curr_sound = [0, 0]
chosen_sound = "m"
word_struc[curr_sound[0]][curr_sound[1]] = chosen_sound


[["m", ""], [""], ["m", ""]]

Instead of going into the correct index and only the correct index, the string is put into the same index of every sublist that is the same length.

I know my code will look pretty clunky and repetitive to someone more experienced; I only learned the basics of python because I took a programming class in high school.

BearCoder01 (8)

I got this output: [['sk', 'ei', '']]. What output do you want?

kaedyngrice (1)

@BearCoder01 The program is randomized. If you keep rerunning the program until you get an output with more than one sublist, you should see the problem I'm having

BearCoder01 (8)

@kaedyngrice Do you get an error if yes one which line?

kaedyngrice (1)

@BearCoder01 No, I don't get any errors.