September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1 +1 @@
|
|||
raw_input()[::-1]
|
||||
input()[::-1]
|
||||
|
|
|
|||
|
|
@ -1,25 +1,11 @@
|
|||
'''
|
||||
Reverse a Unicode string with proper handling of combining characters
|
||||
'''
|
||||
|
||||
import unicodedata
|
||||
|
||||
def ureverse(ustring):
|
||||
'''
|
||||
Reverse a string including unicode combining characters
|
||||
|
||||
Example:
|
||||
>>> ucode = ''.join( chr(int(n, 16))
|
||||
for n in ['61', '73', '20dd', '64', '66', '305'] )
|
||||
>>> ucoderev = ureverse(ucode)
|
||||
>>> ['%x' % ord(char) for char in ucoderev]
|
||||
['66', '305', '64', '73', '20dd', '61']
|
||||
>>>
|
||||
'''
|
||||
'Reverse a string including unicode combining characters'
|
||||
groupedchars = []
|
||||
uchar = list(ustring)
|
||||
while uchar:
|
||||
if 'COMBINING' in unicodedata.name(uchar[0], ''):
|
||||
if unicodedata.combining(uchar[0]) != 0:
|
||||
groupedchars[-1] += uchar.pop(0)
|
||||
else:
|
||||
groupedchars.append(uchar.pop(0))
|
||||
|
|
@ -28,9 +14,16 @@ def ureverse(ustring):
|
|||
|
||||
return ''.join(groupedchars)
|
||||
|
||||
def say_string(s):
|
||||
return ' '.join([s, '=', ' | '.join(unicodedata.name(ch, '') for ch in s)])
|
||||
|
||||
def say_rev(s):
|
||||
print(f"Input: {say_string(s)}")
|
||||
print(f"Character reversed: {say_string(s[::-1])}")
|
||||
print(f"Unicode reversed: {say_string(ureverse(s))}")
|
||||
print(f"Unicode reverse²: {say_string(ureverse(ureverse(s)))}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
ucode = ''.join( chr(int(n, 16))
|
||||
for n in ['61', '73', '20dd', '64', '66', '305'] )
|
||||
ucoderev = ureverse(ucode)
|
||||
print (ucode)
|
||||
print (ucoderev)
|
||||
ucode = ''.join(chr(int(n[2:], 16)) for n in
|
||||
'U+0041 U+030A U+0073 U+0074 U+0072 U+006F U+0308 U+006D'.split())
|
||||
say_rev(ucode)
|
||||
|
|
|
|||
3
Task/Reverse-a-string/Python/reverse-a-string-5.py
Normal file
3
Task/Reverse-a-string/Python/reverse-a-string-5.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ucode = ''.join(chr(int(n[2:], 16)) for n in
|
||||
'U+006B U+0301 U+0075 U+032D U+006F U+0304 U+0301 U+006E'.split())
|
||||
say_rev(ucode)
|
||||
3
Task/Reverse-a-string/Python/reverse-a-string-6.py
Normal file
3
Task/Reverse-a-string/Python/reverse-a-string-6.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ucode = ''.join(chr(int(n, 16))
|
||||
for n in ['61', '73', '20dd', '64', '66', '305'])
|
||||
say_rev(ucode)
|
||||
Loading…
Add table
Add a link
Reference in a new issue