Find element input inside the Python matrix

Asked

Viewed 794 times

0

I’m trying to locate a number’s index inside a list of pre-established lists. The program recognizes the number but says it is not on the list.

i=[[33,59],[34,60],[35,61],[36,62],[37,63],[38,64],[39,65],[40,66],[41,67],[42,68],[43,69],[44,70],[45,71],[46,72],[47,73],[48,74],[49,75],[50,76],[51,77],[52,78],[53,79],[54,80],[55,81],[56,82],[57,83],[58,84]]
senha="senhasenha"
x=""
k=""
y=0
for a in senha:
    j=(ord(a)-97)
    x+=(chr(i[j][y]))
    y+=1
    if(y>1):
        y=0
print (x)
for w in x:
  k=int(ord(w))
  print(i.index(k))

the return stays like this

`3?.B!M%H(; 

Traceback (Most recent call last): File "main.py", line 16, in print(i.index(k)) Valueerror: 51 is not in list`

how can I access this information?

1 answer

1


The problem is that you are trying to access the number through the list of lists. For it to work, you must access the number in the lists that are inside the list i. Implement this:

for w in x:
    k = ord(w)
    for lista in i:
        if k in lista:
            print("j =",i.index(lista),"y =",lista.index(k),"letra =",chr(i.index(lista)+97))

In the code above, I get the variable j receiving the list position within the list list and get the variable y receiving the position of the value in the list. I also put to print the letter of that key, doing the reverse way of generating a letter key.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.