Ask coding questions

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

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

Input:

word_struc = [["", ""], [""], ["", ""]]
curr_sound = [0, 0]
chosen_sound = "m"
word_struc[curr_sound[0]][curr_sound[1]] = chosen_sound
print(word_struc)

Output:

[["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.

Comments
hotnewtop
Coder100 (18057)

anyways that's not supposed to happen whatsoever, it should only index the first item of the first array of the array.

However, your code does that exactly, not your example.

kaedyngrice (1)

@Coder100 Sorry I just realized I added the wrong repl. It's the right one now

Coder100 (18057)

uh that's not a valid array

did you mean

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