How do I trim the output of Python Pyenchat Module's 'suggested words list ? Quite often it gives me a huge list of 20 suggested words that looks awkward when displayed on the screen and also has a tendency to go out of the screen .
Asked
Active
Viewed 573 times
0
-
What have you done so far? Where is your code so far? You have not checked for example documentation like http://docs.python.org/release/2.5.2/lib/expat-example.html - where is the specific problem? – May 26 '11 at 09:43
-
@Sentinel: what is the relevance of outdated (**2.5.2**) documentation of the **expat** module? – John Machin May 26 '11 at 12:32
2 Answers
1
Like sentinel, I'm not sure if the problem you're having is specific to pyenchant or a python-familiarity issue. If I assume the latter, you could simply select the number of values you'd like as part of your program. In simple form, this could be as easy as:
suggestion_list = pyenchant_function(document_filled_with_typos)
number_of_suggestions = len(suggestion_list)
MAX_SUGGESTIONS = 3 # you choose what you like
if number_of_suggestions > MAX_SUGGESTIONS:
answer = suggestion_list[0:(MAX_Suggestions-1)] # python lists are indexed to 0
else:
answer = suggestion_list
Note: I'm choosing to be clear rather than concise here, since I'm guessing that will be valued by asker, if asker is unclear on using list indices.
Hope this helps and good luck with python.

Profane
- 1,128
- 8
- 13
0
Assuming it returns a standard Python list, you use standard Python slicing syntax. E.g. suggestedwords[:10]
gets just the first 10.

Thomas K
- 39,200
- 7
- 84
- 86