diff --git a/Ketikan_yang_rusak b/Ketikan_yang_rusak new file mode 100644 index 0000000..51bc7b5 --- /dev/null +++ b/Ketikan_yang_rusak @@ -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}")