Reverse Hiragana and Katakana in Python2.7

Thing you want to do

--Doraemon => Doraemon

What i did

text = u'Doraemon New Nobita's Great Demon'
d = dict([(x, unichr(x - 0x60)) for x in xrange(ord(u'A'), ord(u'Vu')+1)] + [(x - 0x60, unichr(x)) for x in xrange(ord(u'A'), ord(u'Vu')+1)])
print text.translate(d)

result

Doraemon New Nobita's Great Demon

what's this?

--Using the fact that the difference between UTF-8 Hiragana and Katakana is 0x60, create a map of Hiragana → Katakana and Katakana → Hiragana. --Translate using str.translate.

I'm only thinking about unicode, so input validation may be necessary.

Recommended Posts

Reverse Hiragana and Katakana in Python2.7
Pandas
Reverse Hiragana and Katakana in Python2.7
Reverse strings in Python
Stack and Queue in Python
Unittest and CI in Python
About Python sort () and reverse ()
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
Difference between == and is in python
View photos in Python and html
Sorting algorithm and implementation in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Assignments and changes in Python objects
Check and move directories in Python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Function synthesis and application in Python
Export and output files in Python
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Create and read messagepacks in Python
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Modules and packages in Python are "namespaces"
Avoid nested loops in PHP and Python
Differences between Ruby and Python in scope
AM modulation and demodulation in Python Part 2
difference between statements (statements) and expressions (expressions) in Python
Implementation module "deque" in queue and Python
Line graphs and scale lines in python
Implement FIR filters in Python and C
Differences in syntax between Python and Java
Check and receive Serial port in Python (Port check)
Difference between @classmethod and @staticmethod in Python
Difference between append and + = in Python list
Difference between nonlocal and global in Python
Write O_SYNC file in C and Python
Dealing with "years and months" in Python
Read and write JSON files in Python
Easily graph data in shell and Python
Private methods and fields in python [encryption]
Find and check inverse matrix in Python
Linear Independence and Basis: Linear Algebra in Python <6>
Differences in multithreading between Python and Jython
Module import and exception handling in python
How to use is and == in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
nCr in python