Documentation for version v0.48.0 is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.
Dictionaries
#@ color = {"red": 123, "yellow": 100, "blue": "245"}
red: #@ color["red"]
Copied here for convenience from Starlark specification.
- dict·clear (
D.clear()
)
x = {"one": 1, "two": 2}
x.clear() # None
print(x) # {}
- dict·get (
D.get(key[, default])
)
x = {"one": 1, "two": 2}
x.get("one") # 1
x.get("three") # None
x.get("three", 0) # 0
- dict·items (
D.items()
)
x = {"one": 1, "two": 2}
x.items() # [("one", 1), ("two", 2)]
- dict·keys (
D.keys()
)
x = {"one": 1, "two": 2}
x.keys() # ["one", "two"]
- dict·pop (
D.pop(key[, default])
)
x = {"one": 1, "two": 2}
x.pop("one") # 1
x # {"two": 2}
x.pop("three", 0) # 0
x.pop("four") # error: missing key
- dict·popitem (
D.popitem()
)
x = {"one": 1, "two": 2}
x.popitem() # ("one", 1)
x.popitem() # ("two", 2)
x.popitem() # error: empty dict
- dict·setdefault (
D.setdefault(key[, default])
)
x = {"one": 1, "two": 2}
x.setdefault("one") # 1
x.setdefault("three", 0) # 0
x # {"one": 1, "two": 2, "three": 0}
x.setdefault("four") # None
x # {"one": 1, "two": 2, "three": None}
- dict·update (
D.update([pairs][, name=value[, ...])
)
x = {}
x.update([("a", 1), ("b", 2)], c=3)
x.update({"d": 4})
x.update(e=5)
x # {"a": 1, "b": "2", "c": 3, "d": 4, "e": 5}
- dict·values (
D.values()
)
x = {"one": 1, "two": 2}
x.values() # [1, 2]
(Help improve our docs: edit this page on GitHub)