Skip to content

Dictionaries

Ferenc Bodon edited this page May 28, 2018 · 12 revisions

Creation

command Q Python Q example Python example comment
creating dictionary ! { } d: `a`b`c!3 1 2 d = {"a": 3, "b": 1, "c": 2}
💛 dictionary of a single item keyword enlist no special treatment enlist[`a]!enlist 3 {"a":3} Need of using enlist is confusing
💛 creating dictionary from list of pairs . ! flip dict .[!; flip ((`a; 3); (`b;1)] dict([('a', 3), ('b', 1)])
💙 from two lists ! dict + zip keyList!valueList dict(zip(keyList, valueList))

Modification

command Q Python Q example Python example comment
removing an element delete `del delete `a from `d del d["a"]

Lookup

command Q Python Q example Python example comment
has given key in key in `a in key m "a" in m

Operations

command Q Python Q example Python example comment
💙 sort by value ascendingly asc sorted, package: operator asc d sorted(d.items(), key=operator.itemgetter(1))

Clone this wiki locally