Skip to content

Instantly share code, notes, and snippets.

@mcvarer
Last active January 31, 2021 18:03
Show Gist options
  • Save mcvarer/5a6f30e4ae8c348337671ea8c9bdd07f to your computer and use it in GitHub Desktop.
Save mcvarer/5a6f30e4ae8c348337671ea8c9bdd07f to your computer and use it in GitHub Desktop.
import re
alfabe = ['a', 'b', 'c', 'ç', 'd', 'e', 'f', 'g', 'ğ', 'h', 'ı', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'ö', 'p', 'r', 's', 'ş', 't', 'u', 'ü', 'v', 'y', 'z']
def pangram(sentence):
# sentence = sentence.replace(" ", "").lower()
sentence = re.sub("\W", '', sentence).lower()
used = []
[used.append(harf) for harf in sentence if harf in alfabe and harf not in used]
not_used = []
[not_used.append(alp) for alp in alfabe if alp not in used]
if len(used) + len(not_used) == 29 and len(sentence) < 34:
print("Tebrikler Tüm harflari kullanarak ve 34 harftan aşağı kelime ile başardınız.")
return f"Kullan Harf Sayısı : {len(used)} \
Kullanılmayan Harf Sayısı : {len(not_used)}" \
f" Cümledeki toplam Harf Sayısı : {len(sentence)}"
print(pangram("Saf ve haydut kız çocuğu bin plaj görmüş."))
##### OUTPUT #####
# Tebrikler Tüm harflari kullanarak ve 34 harftan aşağı kelime ile başardınız.
# Kullan Harf Sayısı : 29 Kullanılmayan Harf Sayısı : 0
# Cümledeki toplam Harf Sayısı : 33
@mcvarer
Copy link
Author

mcvarer commented Jan 31, 2021

Şu anda noktalama işaretleriyle ilgili bir problem görüyorum, sentence.replace yerine aşağıdaki yöntem işini görecektir.

import re
...
sentence = re.sub("\W", '', sentence)

Haklısınız fakat sonuna .lower() eklenmeli. Bu şekilde doğru çalışacaktır.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment