Supports de cours Pilot Systems
 
You are here: Home Cours à l'INSIA Cours de Python à l'INSIA, pour ING1 et ING2SRT TP1 : fichier words.py
Document Actions

TP1 : fichier words.py

by gael last modified 2008-03-17 16:03

Click here to get the file

Size 1 kB - File type text/python-source

File contents

# -*- coding: iso-8859-1 -*-

DELIMITERS = '.,;:!?()«»"-+'
SEPARATORS = '.!?'

def words(source):
    """
    Generator that iterates on the lines of source, and returns words.
    """
    for line in source:
        words = line.split()
        for word in words:
            yield word.strip()


def clean_words(source):
    """
    Clean the words, and adds SEP at the beginning and end of sentences
    """
    yield "SEP"
    for word in words(source):
        sep = False
        word = word.lower()
        if word[-1] in SEPARATORS:
            sep = True
        word = word.strip(DELIMITERS)
        if word:
            yield word
        if sep:
            yield "SEP"
        
Contactez-nous

01 44 53 05 55

 
Plan du site
Sites
  © 1999-2008 Pilot Systems - Powered by Plone 9, rue Desargues, 75011 Paris
France — 01 44 53 05 55