Search code examples
pythonlistord

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


Solution

  • 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]