0

I know the question sounds weird but essentially I have a list of words and I want the nth element of that list to be equal to the [n][0] element in another 2D list. So if my list of words is:

words = ["illuminated", "animosity", "deoxyribonucleic", "container", "lit", "amity", "encourage", "lighted"]

then in a separate 2Dwords list I want it such that element [1][0] is 'animosity' and element [4][0] is 'lit'. I have the following code written:

twoDword = [[0]*3]*len(words)
    for i in range(len(twoDword)):
        twoDword[i][0] = words[i]
    print(twoDword)

However when I do this on the list of words I had in the previous code block, my output is the following:

[['lighted', 0, 0], ['lighted', 0, 0], ['lighted', 0, 0], ['lighted', 0, 0], ['lighted', 0, 0], ['lighted', 0, 0], ['lighted', 0, 0], ['lighted', 0, 0]]

when what I want is

[['illuminated', 0, 0], ['animosity', 0, 0], ['deoxyribonucleic', 0, 0], ['container', 0, 0], ['lit', 0, 0], ['amity', 0, 0], ['encourage', 0, 0], ['lighted', 0, 0]]
Pratik M
  • 3
  • 2

0 Answers0