Add Ketikan_yang_rusak
This commit is contained in:
parent
b1ccf87a40
commit
fdc83ab177
33
Ketikan_yang_rusak
Normal file
33
Ketikan_yang_rusak
Normal file
@ -0,0 +1,33 @@
|
||||
def clean_text(input_text):
|
||||
"""
|
||||
Fungsi untuk membersihkan teks dengan menghapus huruf yang berulang secara berlebihan.
|
||||
:param input_text: String, kalimat yang akan dibersihkan
|
||||
:return: String, kalimat yang telah dibersihkan
|
||||
"""
|
||||
cleaned_text = []
|
||||
for sentence in input_text:
|
||||
cleaned_sentence = []
|
||||
prev_char = ""
|
||||
for char in sentence:
|
||||
if char != prev_char:
|
||||
cleaned_sentence.append(char)
|
||||
prev_char = char
|
||||
cleaned_text.append("".join(cleaned_sentence))
|
||||
return cleaned_text
|
||||
|
||||
|
||||
# Contoh penggunaan
|
||||
if __name__ == "__main__":
|
||||
# Input kalimat
|
||||
sentences = [
|
||||
"rummmahhhhhhhh ssssssaaaaakiiiitttttt",
|
||||
"botakkkkkk sukaaaaaaa makannnnnnnn",
|
||||
"sekarangggg hariii mingguuuuuu"
|
||||
]
|
||||
|
||||
# Membersihkan kalimat
|
||||
corrected_sentences = clean_text(sentences)
|
||||
|
||||
# Output hasil
|
||||
for i, corrected in enumerate(corrected_sentences, 1):
|
||||
print(f"h#{i}: {corrected}")
|
Loading…
x
Reference in New Issue
Block a user