Strange, when I run your code all n-grams have value 1.
Does thas mean that t is a key and t[1] is a value in this dictionary?
Output: WIKIBOOKS RESOURCES: 1
RESOURCES FROM: 1
FROM WIKIVERSITY: 1
WIKIVERSITY OFFICIAL: 1
OFFICIAL WEBSITE: 1
WEBSITE PYTHON: 1
AT CURLIE: 1
CURLIE VTEPROGRAMMING: 1
VTEPROGRAMMING LANGUAGES: 1
LANGUAGES COMPARISON: 1
COMPARISON TIMELINE: 1
TIMELINE HISTORY: 1
HISTORY APL: 1
APL ASSEMBLY: 1
ASSEMBLY BASIC: 1
BASIC COBOL: 1
COBOL FORTRAN: 1
FORTRAN GO: 1
GO GROOVY: 1
GROOVY HASKELL: 1
HASKELL JAVA: 1
JAVA JAVASCRIPT: 1
JAVASCRIPT JS: 1
JS JULIA: 1
JULIA KOTLIN: 1
KOTLIN LISP: 1
LISP LUA: 1
etc.
(Mar-02-2019, 02:12 AM)ichabod801 Wrote:(Mar-01-2019, 11:28 PM)Truman Wrote: Could you also give me an explanation of this line:
Python Code: (Double-click to select all)
1
ngrams = OrderedDict(sorted(ngrams.items(), key=lambda t: t[1], reverse=True))
Particulary this chunk: key=lambda t: t[1]
Don't understand what is it for...
I'm not familiar with the packages you are using, but I can help you with this bit. The key parameter to sorted (or list.sort()) is a function that the value to actually do the sort by. This is very often done as a lambda function. If you are not familiar with those, they are simple throw-away functions. They have one expression, and the value of that expression is the return value of the function. In this case you are sorting dictionary items, which are key/value pairs. So if t is a dictionary item, t[1] is the value. It's returning the key/value pairs from the dictionary, sorted by the values.
Does thas mean that t is a key and t[1] is a value in this dictionary?