Home > Software engineering >  How do i convert a modified list of The Alphabet into a number?
How do i convert a modified list of The Alphabet into a number?

Time:11-08

i want to convert the sentence from variable (salam) into numbers. The conversion table is like a modified alphabet just like in (char2). My expected output is a 3x3 matrix, inside is the converted number from(salam) using (char2)

salam = "APAKABARBROOOOO"
salam = salam.lower
output = []
char2 = [' ','a','b','c','d','e','f','g','h','i','j','k','l',
               'm','n','o','p','q','r','s','t','u','v','w','x','y','z','.',',']
i = 0
while i <= 15:
    np.array(char2.index(salam[i]))
    i = i 1

and the output is

Traceback (most recent call last):
  File "C:\Users\dragg\testing funtction losaot[sn[ga\main.py", line 12, in <module>
    np.array(char2.index(salam[i]))
TypeError: 'builtin_function_or_method' object is not subscriptable

here is the image for clarity enter image description here

CodePudding user response:

The problem is from salam.lower. It should be salam.lower(). Without the () you are just referencing the .lower object.

  • Related