Import all letters of an alphabet in a certain language in python

一世执手 提交于 2020-06-17 09:45:42

问题


Could it be possible to import all the possible letters (lowercase, uppercase, etc.) in an alphabet in a certain language (Turkish, Polish, Russian, etc.) as a python list? Is there a certain module to do that?

Thanks & Best Regards

Michael


回答1:


Your question ties into a larger problem - how alphabets of certain languages are stored in a computer, how they are represented, and (eventually) how they can be retrieved in Python?

I suggest you read:

  • The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
  • Unicode & Character Encodings in Python: A Painless Guide

The short answer is - "yes". But it depends on what you actually name an alphabet of the language (e.g. in some languages there are specific characters for punctuation. do you consider them as part of the alphabet in your application?) What do you need it for? If it is about language detection then there is a duplicate question. Your question is generic and without details and (best) a snippet it will be difficult to be answered satisfactorily for you.




回答2:


If I have understood your question, you want a list with all letters from an alphabet. A possible solution may be:

  • get a string with the full alphabet you need
  • use a set() to transform the string in a collection of unique, non ordered elements.

Then you can use the collection to do a lot of things, as explained in docs.python.org, section 5.4:

a = set('abracadabra')
b = set('alacazam')
a                                  # unique letters in a
   {'a', 'r', 'b', 'c', 'd'}
a - b                              # letters in a but not in b
   {'r', 'd', 'b'}
a | b                              # letters in a or b or both
   {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
a & b                              # letters in both a and b
   {'a', 'c'}
a ^ b                              # letters in a or b but not both
   {'r', 'd', 'b', 'm', 'z', 'l'}


来源:https://stackoverflow.com/questions/61182560/import-all-letters-of-an-alphabet-in-a-certain-language-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!