matrix.append(list(newlist[x:x+6]))
You append 6 element lists to matrix
, but you try to unpack them into two variables later:
for y, vector in matrix:
The numbers have to match.
Currently you matrix
looks like [ [4,3,2,6,3,2], [2,1,6,8,9,2], ... ]
. How is python supposed to unpack one of the elements, for example [4,3,2,6,3,2]
into y
and vector
? What should go where? (For possible solutions see the other answers, they were faster. I don't understand what behaviour is expected anyway.)
Also you cannot index a character:
codedmessage.append(letter[x], letter[y])
previously you assigned a single character to letter
, here:
for letter in message:
because message
is a string. You probably confuse names as you already have assigned a string to letter
initially: letter = "ABCDEF"
Probably you want to use two different names.
append
does only take one argument, too. Again I don't know what you expect, but I guess it should be either codedmessage.append([letter[x], letter[y]])
or codedmessage += [letter[x], letter[y]]
.
I also highly doubt that you want to use x
in codedmessage.append(letter[x], letter[y])
because you only used x
in another independent loop as iteration variable.