Issue
I have this Unicode string:
my_string = "₁ᴀa̲a̲̲"
How can index and slice it to make other Unicode strings?
If I run
print([x for x in my_string])
['₁', 'ᴀ', 'a', '̲', 'a', '̲', '̲']
when I expected
['₁', 'ᴀ', 'a̲', '̲a̲̲']
this prints
my_string[3]
'̲'
when I expected
a̲̲
I tried t define
my_string = u"₁ᴀa̲a̲̲"
but the u
is automatically deleted by vscode
I need my_string
as buffer to compose other strings according to his human-readable index.
Solution
You could use the \X
regex and findall
from the regex
module:
import regex
out = regex.findall(r'\X', my_string)
Output:
['₁', 'ᴀ', 'a̲', 'a̲̲']
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.