Форум сайта python.su
thanqurewelcome
Напишите код, который будет рещать следующую задачу
thanqurewelcome: D
новичку-девушке
Офлайн
Неужели на филфаке стали заставлять программировать?
Офлайн
thanqurewelcomeи какие могут быть вопросы ?
Внимание: для решения этой задачи достаточно того, что уже было рассмотрено на занятиях.
Офлайн
import re sentences = 'Computational linguistics is an interdisciplinary field concerned with the statistical or rule-based modeling of natural language from a computational perspective.', 'Traditionally, computational linguistics was usually performed by computer scientists who had specialized in the application of computers to the processing of a natural language.', ' Computational linguists often work as members of interdisciplinary teams, including linguists (specifically trained in linguistics), language experts (persons with some level of ability in the languages relevant to a given project), and computer scientists.', ' In general, computational linguistics draws upon the involvement of linguists, computer scientists, experts in artificial intelligence, mathematicians, logicians, philosophers, cognitive scientists, cognitive psychologists, psycholinguists, anthropologists and neuroscientists, among others.', 'Computational linguistics has theoretical and applied components, where theoretical computational linguistics takes up issues in theoretical linguistics and cognitive science, and applied computational linguistics focuses on the practical outcome of modeling human language use.' word = 'computer' regex = re.compile('(?:^|\W){}(?:\W|$)'.format(word), re.I) for sentence in sentences: if regex.search(sentence): print(sentence)
Офлайн
sergeek
чего ты всяким трансам помогаешь ?
Офлайн
Singularityне знаю, мне нравится
sergeekчего ты всяким трансам помогаешь ?
import re mark_spec = { 'ellipsis ' : ' \.{3} ?' ,'dot' : '\. ?' ,'comma' : ', ?' ,'exclamation mark' : '! ?' ,'question mark' : '\? ?' ,'colon' : ': ' ,'dash' : ' - ?' } regex = re.compile('(?:{})+'.format('|'.join(mark_spec.values()))) def split(text): for name, mark in mark_spec.items(): if re.search(mark, text): print('...see {} here'.format(name)) print('The segments of your text are:') for s in re.split(regex, text): print(s) def main(): while True: split(input('Your text, please: ').replace('"','')) main()
Офлайн