Sundrah
Sundrah

Reputation: 865

Python: How to convert all values in a list to their ascii values?

def encrypt_message(text, x):
  text = list(text)
  for y in text:
    ord(text)

returns ord() expected a string of length 1, but list found

Upvotes: 1

Views: 695

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

The problem is that you passed the text to ord function you need to pass the y.

But as strings are iterable objects you can just loop over your string :

def encrypt_message(text, x):
     return [ord(i) for i in text]

Upvotes: 1

Related Questions