[PYTHON] I want to split a character string with hiragana

Divide sentences with hiragana

I decided to add ruby text in kanji. I made it in the process. Code below

def hiragana_split(s):
    #Divide the original text with hiragana
    #List of Japanese syllabary
    fifty_text = [chr(i) for i in range(12353, 12436)] + ['。', '、']
    split_list = []
    #Whether it is hiragana
    start_point = 0
    section = ''
    for i in range(len(s) - 1):
        if not (s[i] in fifty_text) == (s[i + 1] in fifty_text):
            split_list += [s[start_point:i + 1]]
            start_point = i + 1
    return split_list


if __name__ == '__main__':
    s = 'I have no idea where I was born. I remember only crying in a dim and damp place.'
    print(hiragana_split(s))
# ['where', 'Raw', 'It was', 'Register', 'I can't get it.', 'what', 'But', 'Dim', 'Bullying', 'Place', 'so', 'Meow meow crying', 'Was there', 'Thing', 'Only', 'Memory']

Recommended Posts

I want to split a character string with hiragana
[Introduction to Python] How to split a character string with the split function
I want to make a game with Python
I tried to generate a random character string
I want to write to a file with Python
[Question] I want to scrape a character string surrounded by unique tags!
I want to embed a variable in a Python string
I want to transition with a button in flask
I want to climb a mountain with reinforcement learning
I want to work with a robot in python.
I want to manually create a legend with matplotlib
I want to run a quantum computer with Python
I want to bind a local variable with lambda
I want to do ○○ with Pandas
I want to debug with Python
I want to make a blog editor with django admin
I want to start a jupyter environment with one command
I want to make a click macro with pyautogui (desire)
I want to make a click macro with pyautogui (outlook)
I want to use a virtual environment with jupyter notebook!
I want to convert an ISO-8601 character string to Japan time
I want to install a package from requirements.txt with poetry
[Visualization] I want to draw a beautiful graph with Plotly
I tried to automatically generate a character string to be input to Mr. Adjustment with Python
I want to detect objects with OpenCV
I want to use a wildcard that I want to shell with Python remove
I made a character counter with Python
I want to blog with Jupyter Notebook
Try to extract a character string from an image with Python3
I want to build a Python environment
I want to pip install with PythonAnywhere
[Python] How to invert a character string
I want to do a full text search with elasticsearch + python
I want to play with aws with python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I want to extract an arbitrary URL from the character string of the html source with python
I want to specify a file that is not a character string for logrotate, but is it impossible?
(Matplotlib) I want to draw a graph with a size specified in pixels
Mayungo's Python Learning Episode 6: I tried to convert a character string to a number
I want to batch convert the result of "string" .split () in Python
I want to color a part of an Excel string in Python
[Introduction to Python] How to write a character string with the format function
I want to make matplotlib a dark theme
I want to easily create a Noise Model
I want to use MATLAB feval with python
I want to analyze songs with Spotify API 2
I want to create a window in Python
I want to mock datetime.datetime.now () even with pytest!
I want to display multiple images with matplotlib.
I want to knock 100 data sciences with Colaboratory
I want to be an OREMO with setParam!
I don't want to take a coding test
I want to analyze songs with Spotify API 1
I don't want to use -inf with np.log
#Unresolved I want to compile gobject-introspection with Python3
I want to create a plug-in type implementation
I want to use ip vrf with SONiC
I want to solve APG4b with Python (Chapter 2)
I want to start over with Django's Migrate
I want to easily find a delicious restaurant
I want to upload a Django app to heroku