Exploring Unicode
Possibly pointless
Created: 2021-04-30
Occasionally, I find myself googling something like:
unicode arrow symbol
So I can use a:
→
instead of a:
==> --->
Python includes a database of Unicode symbols so why Google it?
Unicodedata
If you're lucky enough to know the exact name of your desired symbol, getting the character is straight forward.
import unicodedata
>>> unicodedata.lookup("RIGHTWARDS ARROW")
>>> '→'
How can we find characters with 'ARROW' in their name?
Building a Mapping
What we'd like to do is build a mapping of:
CHARACTER NAME: CHARACTER
So we can run a query along the lines of:
{k: v for k, v in mapping.items() if 'ARROW' in k}
Getting Ready
Roughly speaking we want to do something where:
unicodedata.name
provides a canonical name- We generate the character itself
We know that ord
will return a code point for a given character. Conversely, chr
will return a Unicode string from an ordinal
From the documentation, chr
will accept values from 0 <= i <= 0x10ffff
0x10ffff
is hexadecimal format, (base 16). To see the 'normal' way (base 10):
>>> int('0x10ffff', base=16)
>>> 1114111
Although there isn't any need to convert it. The 0x
prefix denotes the hexadecimal format:
>>> 0x10
>>> 16
>>> 0x10 + 16
>>> 32
>>> range(0x1000)
>>> range(0, 4096)
Building
import unicodedata
char_mapping = {}
for i in range(0x10ffff):
character = chr(i)
try:
character_name = unicodedata.name(character)
except ValueError:
continue
char_mapping[character_name] = character
Querying
having_tokens = ["ARROW", "RIGHT"]
not_having_token = ["LEFT"]
def token_filter(char_name, has=having_tokens, has_not=not_having_token):
return all([
all([token in char_name for token in has]),
all([token not in char_name for token in has_not]),
])
arrows = {k: v for k, v in char_mapping.items() if token_filter(k)}
for k, v in arrows.items():
print(f"{k} : {v}")
MODIFIER LETTER RIGHT ARROWHEAD : ˃ MODIFIER LETTER LOW RIGHT ARROWHEAD : ˲ COMBINING RIGHT ARROWHEAD ABOVE : ͐ COMBINING RIGHT ARROWHEAD BELOW : ͕ COMBINING RIGHT ARROWHEAD AND UP ARROWHEAD BELOW : ͖ COMBINING DOUBLE RIGHTWARDS ARROW BELOW : ͢ ARABIC RIGHT ARROWHEAD ABOVE : ࣸ ARABIC RIGHT ARROWHEAD BELOW : ࣺ ARABIC DOUBLE RIGHT ARROWHEAD ABOVE : ࣻ ARABIC DOUBLE RIGHT ARROWHEAD ABOVE WITH DOT : ࣼ ARABIC RIGHT ARROWHEAD ABOVE WITH DOT : ࣽ COMBINING RIGHT ARROWHEAD AND DOWN ARROWHEAD BELOW : ᷿ COMBINING RIGHT ARROW ABOVE : ⃗ COMBINING RIGHT ARROW BELOW : ⃯ RIGHTWARDS ARROW : → RIGHTWARDS ARROW WITH STROKE : ↛ RIGHTWARDS WAVE ARROW : ↝ RIGHTWARDS TWO HEADED ARROW : ↠ RIGHTWARDS ARROW WITH TAIL : ↣ RIGHTWARDS ARROW FROM BAR : ↦ RIGHTWARDS ARROW WITH HOOK : ↪ RIGHTWARDS ARROW WITH LOOP : ↬ UPWARDS ARROW WITH TIP RIGHTWARDS : ↱ DOWNWARDS ARROW WITH TIP RIGHTWARDS : ↳ RIGHTWARDS ARROW WITH CORNER DOWNWARDS : ↴ RIGHTWARDS PAIRED ARROWS : ⇉ RIGHTWARDS DOUBLE ARROW WITH STROKE : ⇏ RIGHTWARDS DOUBLE ARROW : ⇒ RIGHTWARDS TRIPLE ARROW : ⇛ RIGHTWARDS SQUIGGLE ARROW : ⇝ RIGHTWARDS DASHED ARROW : ⇢ RIGHTWARDS ARROW TO BAR : ⇥ RIGHTWARDS WHITE ARROW : ⇨ RIGHTWARDS WHITE ARROW FROM WALL : ⇰ RIGHT ARROW WITH SMALL CIRCLE : ⇴ THREE RIGHTWARDS ARROWS : ⇶ RIGHTWARDS ARROW WITH VERTICAL STROKE : ⇸ RIGHTWARDS ARROW WITH DOUBLE VERTICAL STROKE : ⇻ RIGHTWARDS OPEN-HEADED ARROW : ⇾ APL FUNCTIONAL SYMBOL QUAD RIGHTWARDS ARROW : ⍈ RIGHT ANGLE WITH DOWNWARDS ZIGZAG ARROW : ⍼ HEAVY WIDE-HEADED RIGHTWARDS ARROW : ➔ HEAVY RIGHTWARDS ARROW : ➙ DRAFTING POINT RIGHTWARDS ARROW : ➛ HEAVY ROUND-TIPPED RIGHTWARDS ARROW : ➜ TRIANGLE-HEADED RIGHTWARDS ARROW : ➝ HEAVY TRIANGLE-HEADED RIGHTWARDS ARROW : ➞ DASHED TRIANGLE-HEADED RIGHTWARDS ARROW : ➟ HEAVY DASHED TRIANGLE-HEADED RIGHTWARDS ARROW : ➠ BLACK RIGHTWARDS ARROW : ➡ THREE-D TOP-LIGHTED RIGHTWARDS ARROWHEAD : ➢ THREE-D BOTTOM-LIGHTED RIGHTWARDS ARROWHEAD : ➣ BLACK RIGHTWARDS ARROWHEAD : ➤ HEAVY BLACK CURVED DOWNWARDS AND RIGHTWARDS ARROW : ➥ HEAVY BLACK CURVED UPWARDS AND RIGHTWARDS ARROW : ➦ SQUAT BLACK RIGHTWARDS ARROW : ➧ HEAVY CONCAVE-POINTED BLACK RIGHTWARDS ARROW : ➨ RIGHT-SHADED WHITE RIGHTWARDS ARROW : ➩ BACK-TILTED SHADOWED WHITE RIGHTWARDS ARROW : ➫ FRONT-TILTED SHADOWED WHITE RIGHTWARDS ARROW : ➬ HEAVY LOWER RIGHT-SHADOWED WHITE RIGHTWARDS ARROW : ➭ HEAVY UPPER RIGHT-SHADOWED WHITE RIGHTWARDS ARROW : ➮ NOTCHED LOWER RIGHT-SHADOWED WHITE RIGHTWARDS ARROW : ➯ NOTCHED UPPER RIGHT-SHADOWED WHITE RIGHTWARDS ARROW : ➱ CIRCLED HEAVY WHITE RIGHTWARDS ARROW : ➲ WHITE-FEATHERED RIGHTWARDS ARROW : ➳ BLACK-FEATHERED RIGHTWARDS ARROW : ➵ HEAVY BLACK-FEATHERED RIGHTWARDS ARROW : ➸ TEARDROP-BARBED RIGHTWARDS ARROW : ➺ HEAVY TEARDROP-SHANKED RIGHTWARDS ARROW : ➻ WEDGE-TAILED RIGHTWARDS ARROW : ➼ HEAVY WEDGE-TAILED RIGHTWARDS ARROW : ➽ OPEN-OUTLINED RIGHTWARDS ARROW : ➾ RIGHT ARROW WITH CIRCLED PLUS : ⟴ LONG RIGHTWARDS ARROW : ⟶ LONG RIGHTWARDS DOUBLE ARROW : ⟹ LONG RIGHTWARDS ARROW FROM BAR : ⟼ LONG RIGHTWARDS DOUBLE ARROW FROM BAR : ⟾ LONG RIGHTWARDS SQUIGGLE ARROW : ⟿ RIGHTWARDS TWO-HEADED ARROW WITH VERTICAL STROKE : ⤀ RIGHTWARDS TWO-HEADED ARROW WITH DOUBLE VERTICAL STROKE : ⤁ RIGHTWARDS DOUBLE ARROW WITH VERTICAL STROKE : ⤃ RIGHTWARDS TWO-HEADED ARROW FROM BAR : ⤅ RIGHTWARDS DOUBLE ARROW FROM BAR : ⤇ RIGHTWARDS DOUBLE DASH ARROW : ⤍ RIGHTWARDS TRIPLE DASH ARROW : ⤏ RIGHTWARDS TWO-HEADED TRIPLE DASH ARROW : ⤐ RIGHTWARDS ARROW WITH DOTTED STEM : ⤑ RIGHTWARDS ARROW WITH TAIL WITH VERTICAL STROKE : ⤔ RIGHTWARDS ARROW WITH TAIL WITH DOUBLE VERTICAL STROKE : ⤕ RIGHTWARDS TWO-HEADED ARROW WITH TAIL : ⤖ RIGHTWARDS TWO-HEADED ARROW WITH TAIL WITH VERTICAL STROKE : ⤗ RIGHTWARDS TWO-HEADED ARROW WITH TAIL WITH DOUBLE VERTICAL STROKE : ⤘ RIGHTWARDS ARROW-TAIL : ⤚ RIGHTWARDS DOUBLE ARROW-TAIL : ⤜ RIGHTWARDS ARROW TO BLACK DIAMOND : ⤞ RIGHTWARDS ARROW FROM BAR TO BLACK DIAMOND : ⤠ WAVE ARROW POINTING DIRECTLY RIGHT : ⤳ ARROW POINTING RIGHTWARDS THEN CURVING UPWARDS : ⤴ ARROW POINTING RIGHTWARDS THEN CURVING DOWNWARDS : ⤵ ARROW POINTING DOWNWARDS THEN CURVING RIGHTWARDS : ⤷ RIGHT-SIDE ARC CLOCKWISE ARROW : ⤸ LOWER RIGHT SEMICIRCULAR CLOCKWISE ARROW : ⤾ RIGHTWARDS ARROW WITH PLUS BELOW : ⥅ RIGHTWARDS ARROW THROUGH X : ⥇ RIGHT DOUBLE ARROW WITH ROUNDED HEAD : ⥰ EQUALS SIGN ABOVE RIGHTWARDS ARROW : ⥱ TILDE OPERATOR ABOVE RIGHTWARDS ARROW : ⥲ RIGHTWARDS ARROW ABOVE TILDE OPERATOR : ⥴ RIGHTWARDS ARROW ABOVE ALMOST EQUAL TO : ⥵ GREATER-THAN ABOVE RIGHTWARDS ARROW : ⥸ SUBSET ABOVE RIGHTWARDS ARROW : ⥹ MEASURED ANGLE WITH OPEN ARM ENDING IN ARROW POINTING UP AND RIGHT : ⦨ MEASURED ANGLE WITH OPEN ARM ENDING IN ARROW POINTING DOWN AND RIGHT : ⦪ MEASURED ANGLE WITH OPEN ARM ENDING IN ARROW POINTING RIGHT AND UP : ⦬ MEASURED ANGLE WITH OPEN ARM ENDING IN ARROW POINTING RIGHT AND DOWN : ⦮ EMPTY SET WITH RIGHT ARROW ABOVE : ⦳ RIGHTWARDS ARROW WITH TIP DOWNWARDS : ⬎ RIGHTWARDS ARROW WITH TIP UPWARDS : ⬏ RIGHTWARDS ARROW THROUGH GREATER-THAN : ⭃ RIGHTWARDS ARROW THROUGH SUPERSET : ⭄ RIGHTWARDS QUADRUPLE ARROW : ⭆ REVERSE TILDE OPERATOR ABOVE RIGHTWARDS ARROW : ⭇ RIGHTWARDS ARROW ABOVE REVERSE ALMOST EQUAL TO : ⭈ RIGHTWARDS ARROW ABOVE REVERSE TILDE OPERATOR : ⭌ RIGHTWARDS TRIANGLE-HEADED ARROW : ⭢ RIGHTWARDS TRIANGLE-HEADED DASHED ARROW : ⭬ RIGHTWARDS TRIANGLE-HEADED ARROW TO BAR : ⭲ RIGHTWARDS TRIANGLE-HEADED ARROW WITH DOUBLE HORIZONTAL STROKE : ⭼ RIGHTWARDS TRIANGLE-HEADED PAIRED ARROWS : ⮆ RIGHTWARDS BLACK CIRCLED WHITE ARROW : ⮊ ANTICLOCKWISE TRIANGLE-HEADED RIGHT U-SHAPED ARROW : ⮌ RIGHTWARDS BLACK ARROW : ⮕ THREE-D RIGHT-LIGHTED UPWARDS EQUILATERAL ARROWHEAD : ⮙ THREE-D TOP-LIGHTED RIGHTWARDS EQUILATERAL ARROWHEAD : ⮚ BLACK RIGHTWARDS EQUILATERAL ARROWHEAD : ⮞ DOWNWARDS TRIANGLE-HEADED ARROW WITH LONG TIP RIGHTWARDS : ⮡ UPWARDS TRIANGLE-HEADED ARROW WITH LONG TIP RIGHTWARDS : ⮣ RIGHTWARDS TRIANGLE-HEADED ARROW WITH LONG TIP UPWARDS : ⮥ RIGHTWARDS TRIANGLE-HEADED ARROW WITH LONG TIP DOWNWARDS : ⮧ BLACK CURVED DOWNWARDS AND RIGHTWARDS ARROW : ⮩ BLACK CURVED UPWARDS AND RIGHTWARDS ARROW : ⮫ BLACK CURVED RIGHTWARDS AND UPWARDS ARROW : ⮭ BLACK CURVED RIGHTWARDS AND DOWNWARDS ARROW : ⮯ RIBBON ARROW DOWN RIGHT : ⮱ RIBBON ARROW UP RIGHT : ⮳ RIBBON ARROW RIGHT UP : ⮵ RIBBON ARROW RIGHT DOWN : ⮷ RIGHTWARDS TWO-HEADED ARROW WITH TRIANGLE ARROWHEADS : ⯮ HALFWIDTH RIGHTWARDS ARROW : → TWISTED RIGHTWARDS ARROWS : 🔀 SOON WITH RIGHTWARDS ARROW ABOVE : 🔜 RIGHTWARDS ARROW WITH SMALL TRIANGLE ARROWHEAD : 🠂 RIGHTWARDS ARROW WITH MEDIUM TRIANGLE ARROWHEAD : 🠆 RIGHTWARDS ARROW WITH LARGE TRIANGLE ARROWHEAD : 🠊 RIGHTWARDS ARROW WITH SMALL EQUILATERAL ARROWHEAD : 🠒 RIGHTWARDS ARROW WITH EQUILATERAL ARROWHEAD : 🠖 HEAVY RIGHTWARDS ARROW WITH EQUILATERAL ARROWHEAD : 🠚 HEAVY RIGHTWARDS ARROW WITH LARGE EQUILATERAL ARROWHEAD : 🠞 RIGHTWARDS TRIANGLE-HEADED ARROW WITH NARROW SHAFT : 🠢 RIGHTWARDS TRIANGLE-HEADED ARROW WITH MEDIUM SHAFT : 🠦 RIGHTWARDS TRIANGLE-HEADED ARROW WITH BOLD SHAFT : 🠪 RIGHTWARDS TRIANGLE-HEADED ARROW WITH HEAVY SHAFT : 🠮 RIGHTWARDS TRIANGLE-HEADED ARROW WITH VERY HEAVY SHAFT : 🠲 RIGHTWARDS FINGER-POST ARROW : 🠶 RIGHTWARDS SQUARED ARROW : 🠺 RIGHTWARDS COMPRESSED ARROW : 🠾 RIGHTWARDS HEAVY COMPRESSED ARROW : 🡂 RIGHTWARDS HEAVY ARROW : 🡆 RIGHTWARDS SANS-SERIF ARROW : 🡒 WIDE-HEADED RIGHTWARDS LIGHT BARB ARROW : 🡢 WIDE-HEADED RIGHTWARDS BARB ARROW : 🡪 WIDE-HEADED RIGHTWARDS MEDIUM BARB ARROW : 🡲 WIDE-HEADED RIGHTWARDS HEAVY BARB ARROW : 🡺 WIDE-HEADED RIGHTWARDS VERY HEAVY BARB ARROW : 🢂 RIGHTWARDS TRIANGLE ARROWHEAD : 🢒 RIGHTWARDS WHITE ARROW WITHIN TRIANGLE ARROWHEAD : 🢖 RIGHTWARDS ARROW WITH NOTCHED TAIL : 🢚 RIGHTWARDS BOTTOM SHADED WHITE ARROW : 🢡 RIGHTWARDS TOP SHADED WHITE ARROW : 🢣 RIGHTWARDS RIGHT-SHADED WHITE ARROW : 🢥 RIGHTWARDS BACK-TILTED SHADOWED WHITE ARROW : 🢩 RIGHTWARDS FRONT-TILTED SHADOWED WHITE ARROW : 🢫