Skip to content Skip to sidebar Skip to footer

Add And Print Non-ascii Characters To A List-python

With the python I have learn, I have been trying to – when you type in a phrase – translate it into symbols. I tried the maketrans() function, but that didn't worked. Here's my

Solution 1:

In python 3, printing lists doesn't use string escape while in Python 2 it does, so doing the same thing in python 3 will achieve the save result you wanted. To achieve the same result in Python 2, you will have to do:

# -*- coding: utf-8 -*-
import sys

message = "ab"
output = []
broke = list(message)
limit = len(broke)

for i in range(limit):
    if broke[i] == "a":
        output.append("¬")
    if broke[i] == "b":
        output.append("∆")
msg = repr(output).decode('string-escape')
print msg

output will be:

['¬', '∆']

Solution 2:

output is a list of strings. Just print the individual strings:

foroutin output:
    print out

Post a Comment for "Add And Print Non-ascii Characters To A List-python"