File size: 3,047 Bytes
bdfde60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# import nbimporter
import nbimporter
from Text2List import text_to_list
def convert_to_list(text, text_list):
    matched_words = []
    unmatched_text = ''  # To accumulate unmatched characters

    # Sort text_list by length in descending order to prioritize longest matches first
    text_list_sorted = sorted(text_list, key=len, reverse=True)

    while text:
        matched = False
        for word in text_list_sorted:
            if text.startswith(word):
                # Add any accumulated unmatched text before appending the matched word
                if unmatched_text:
                    matched_words.append(unmatched_text)
                    unmatched_text = ''  # Reset unmatched text accumulator

                matched_words.append(word)
                text = text[len(word):]  # Remove the matched part from text
                matched = True
                break

        if not matched:
            # Accumulate unmatched characters
            unmatched_text += text[0]
            text = text[1:]

    # If there's any remaining unmatched text, add it to the result
    if unmatched_text:
        matched_words.append(unmatched_text)

    # Join matched words and unmatched text with a space
    result = ' '.join(matched_words)
    return result
    
# text = "जीरोएकदोतीनचारपांचछहसातआठनौदसजीरोएकदोतीनचारपांच"

if __name__=="__main__":
    converted=convert_to_list(text, text_to_list())
    print(converted)


# In[ ]:


# # import nbimporter
# import nbimporter
# from Text2List import text_to_list
# def convert_to_list(text, text_list):
#     matched_words = []
#     unmatched_text = ''  # To accumulate unmatched characters

#     # Sort text_list by length in descending order to prioritize longest matches first
#     text_list_sorted = sorted(text_list, key=len, reverse=True)

#     while text:
#         matched = False
#         for word in text_list_sorted:
#             if word in text:
#                 # Add any accumulated unmatched text before appending the matched word
#                 if unmatched_text:
#                     matched_words.append(unmatched_text)
#                     unmatched_text = ''  # Reset unmatched text accumulator

#                 matched_words.append(word)
#                 text = text[len(word):]  # Remove the matched part from text
#                 matched = True
#                 break

#         if not matched:
#             # Accumulate unmatched characters
#             unmatched_text += text[0]
#             text = text[1:]

#     # If there's any remaining unmatched text, add it to the result
#     if unmatched_text:
#         matched_words.append(unmatched_text)

#     # Join matched words and unmatched text with a space
#     result = ' '.join(matched_words)
#     return result
    
# text = "जीरोएकदोतीनचार"

# if __name__=="__main__":
#     converted=convert_to_list(text, text_to_list())
#     print(converted)