For any ascii characters ch
, I would like to print ch
unless repr(ch)
begins with a back-slash character.
I want to print a list of all of the “nice” ascii characters.
Failed Attempt
JavaScript
x
17
17
1
import re
2
3
4
characters = [chr(num) for num in range(256)]
5
# `characters` : a list such that every element
6
# of the list is an ASCII character
7
8
escaped_chars = [repr(ch)[1:-1] for ch in characters]
9
# `escaped_chars`: a list of all ASCII character unless
10
# the character is special
11
# new line is stored as "n"
12
# carriage return is stored as "r"
13
14
printables = "".join(filter(lambda s: s[0] != "\", escaped_chars))
15
16
print("n".join(re.findall('.{1,20}', "".join(printables))))
17
The console print-out is:
JavaScript
1
11
11
1
!"#$%&'()*+,-./0123
2
456789:;<=>?@ABCDEFG
3
HIJKLMNOPQRSTUVWXYZ[
4
]^_`abcdefghijklmnop
5
qrstuvwxyz{|}~¡¢£¤¥¦
6
§¨©ª«¬®¯°±²³´µ¶·¸¹º»
7
¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ
8
ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâã
9
äåæçèéêëìíîïðñòóôõö÷
10
øùúûüýþÿ
11
I seem to have printed a lot of weird unicode characters, such as ç
and õ
Advertisement
Answer
JavaScript
1
16
16
1
import re
2
3
characters = [chr(num) for num in range(127)]
4
# `characters` : a list such that every element
5
# of the list is an ASCII character
6
7
escaped_chars = [repr(ch)[1:-1] for ch in characters]
8
# `escaped_chars`: a list of all ASCII character unless
9
# the character is special
10
# new line is stored as "n"
11
# carriage return is stored as "r"
12
13
printables = "".join(filter(lambda s: s[0] != "\", escaped_chars))
14
15
print("n".join(re.findall('.{1,20}', "".join(printables))))
16
As sj95126 wrote:
values above 127 aren’t ASCII characters
Here’s right code