[Tutor] swapping list elements based on some criterion
Peter Otten
__peter__ at web.de
Sat Oct 8 09:53:35 CEST 2011
Emad Nawfal (عمـ نوفل ـاد) wrote:
> Here is the function as I used it, and it works fine:
>
> def swap(sentence):
> buffer = []
> adjectives = []
> for word in sentence.split():
> if word.endswith('/ADJ'):
> adjectives.append(word)
> elif word.endswith('/N'):
> buffer.append(word)
> buffer.extend(adjectives)
>
> adjectives = []
> else:
> buffer.append(word)
> return ' '.join(buffer)
Does the classification scheme allow for adjectives that are not followed by
a noun? Example: if "good" in the sentence "That looks good" were classified
as an adjective it would be silently dropped.
More information about the Tutor
mailing list