پڕۆژەیا ژمارتنا پەیڤان
نڤیسینێ پاک بکە، بکە پارچە و پاشی پەیڤان بهژمێرە.
د ڤێ لاپەڕێ دا
بیرۆکا وانەیێ
ئەگەر دڤێت Tea و tea ئێک پەیڤ بن، بەرێ ژمارتنێ هەردوو بکە پیتێن بچووک.
نموونەیا کۆدی
import re
def analyze_words(text):
words = re.findall("[^\\W\\d_]+", text.casefold())
counts = {}
for word in words:
counts[word] = counts.get(word, 0) + 1
ranked = sorted(counts.items(), key=lambda item: (-item[1], item[0]))
return {"total": len(words), "unique": len(counts), "ranking": ranked}
def main():
text = "Python is useful. I learn Python. I write code, code!"
report = analyze_words(text)
print("Total words:", report["total"])
print("Unique words:", report["unique"])
for word, count in report["ranking"]:
print(word, count)
print("Empty text:", analyze_words(""))
if __name__ == "__main__":
main()ئەنجامی بشوپینە
بەرنامە ژمارا هەمی پەیڤان و ژمارا پەیڤێن جودا جودا چاپ دکەت. پەیڤا code دوو جاران هاتییە، لێ د لیستا پەیڤێن جودا دا ئێک جارە.
Total words: 10
Unique words: 7
code 2
i 2
python 2
is 1
learn 1
useful 1
write 1
Empty text: {'total': 0, 'unique': 0, 'ranking': []}هەڵەیەکا بەربەلاڤ
یاسایا پاککرنێ پێش ژمارتنێ دیار بکە دا پیتێن مەزن و بچووک ب هەڵە نەهێنە جوداکرن.