# NodeBox

Create visual output with Python programming code
Home Download Reference Tutorial Library Gallery About

# wordnet.flatten()

## Syntax

    flatten(list)

## Description

Commands like hyponyms() in the WordNet library return a list in which each element itself is a list of related words. Sometimes we just want a simple, flat list of words. This command converts a nested list to a flat list.

## Example

    wordnet = ximport("wordnet")
    feelings = wordnet.hyponyms("feeling")
    feelings = wordnet.flatten(feelings)
    if "pity" in feelings:
      print "pity is a human emotion"

WordNet has information on many many feelings:

    print feelings
    >>> ['feeling', 'affect', 'emotion', 'conditioned emotional response', 'CER',
    >>> 'conditioned emotion', 'anger', 'choler', 'ire', 'fury', 'rage', 'madness',
    >>> 'wrath', 'lividity', 'infuriation', 'enragement', 'umbrage', 'offense',
    >>> 'offence', 'indignation', 'outrage', 'dudgeon', 'high dudgeon', 'huffiness',
    >>> 'dander', 'hackles', 'bad temper', 'ill temper', 'irascibility',
    >>> 'short temper', 'spleen', 'quick temper', 'fit', 'tantrum', 'scene',
    >>> 'conniption', 'annoyance', 'chafe', 'vexation', 'pique', 'temper',
    >>> 'irritation', 'frustration', 'aggravation', 'exasperation', ...