forked from kal179/Beginners_Python_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunicode.py
More file actions
24 lines (20 loc) · 641 Bytes
/
unicode.py
File metadata and controls
24 lines (20 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python
# -*- coding: utf-8 -*-
# returns UNICODE value of a character
def get_ascii(S):
# even if string has only 1 character
# it yields same for all
if len(S) > 0:
for char_ in list(S):
yield((char_, ord(char_)))
# ord returns unicode value of given string of length 1
# we only increased it's capacity
# simple ..eh
# test
test_characters = ['A', 'x', 'Y', 'Z', 'm', 'K', "STack"]
for test_case in test_characters:
print("Test Case: " + test_case)
codes = list(get_ascii(test_case))
for code in codes:
print(" character: {}, unicode_val: {}".format(code[0], code[1]))
print(" ")