PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Random text styling
(just run it multiple times)"""
from collections import namedtuple
from functools import partial
from string import ascii_lowercase, ascii_uppercase
from typing import Callable
from random import choice
# Named tuples let us use object attributes
LetterPair = namedtuple("LetterPair", "lower upper")
styles = "italic bold fractur".split()
uppercases = "𝘈𝐀𝕬"
lowercases = "𝘢𝐚𝖆"
# Dictionary is made from the above iterables
offset = {style: LetterPair(ord(low) - ord("a"),
ord(upp) - ord("A"))
for style, low, upp
in zip(styles, lowercases, uppercases)}
def translate_char(char: str, style: str) -> str:
"""Apply a style to any ascii letter"""
if char in ascii_lowercase:
return chr(ord(char) + offset[style].lower)
if char in ascii_uppercase:
return chr(ord(char) + offset[style].upper)
return char
# Partially applied functions are fun!
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run