Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
348caaf9
Commit
348caaf9
authored
May 02, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: Add _collections module reference.
parent
1f0dfe37
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
docs/library/_collections.rst
docs/library/_collections.rst
+53
-0
docs/library/index.rst
docs/library/index.rst
+3
-0
No files found.
docs/library/_collections.rst
0 → 100644
View file @
348caaf9
:mod:`_collections` -- collection and container types
=====================================================
.. module:: _collections
:synopsis: collection and container types
This module implements advanced collection and container types to
hold/accumulate various objects.
Classes
-------
.. function:: namedtuple(name, fields)
This is factory function to create a new namedtuple type with a specific
name and set of fields. A namedtyple is a subclass of tuple which allows
to access its fields not just by numeric index, but also with an attribute
access syntax using symbolic field names. Fields is a sequence of strings
specifying field names. For compatibily with CPython it can also be a
a string with space-separated field named (but this is less efficient).
Example of use::
from _collections import namedtuple
MyTuple = namedtuple("MyTuple", ("id", "name"))
t1 = MyTuple(1, "foo")
t2 = MyTuple(2, "bar")
print(t1.name)
assert t2.name == t2[1]
.. function:: OrderedDict(...)
``dict`` type subclass which remembers and preserves the order of keys
added. When ordered dict is iterated over, keys/items are returned in
the order they were added::
from _collections import OrderedDict
# To make benefit of ordered keys, OrderedDict should be initialized
# from sequence of (key, value) pairs.
d = OrderedDict([("z", 1), ("a", 2)])
# More items can be added as usual
d["w"] = 5
d["b"] = 3
for k, v in d.items():
print(k, v)
Output::
z 1
a 2
w 5
b 3
docs/library/index.rst
View file @
348caaf9
...
...
@@ -28,6 +28,7 @@ library.
:maxdepth: 1
cmath.rst
_collections.rst
gc.rst
math.rst
select.rst
...
...
@@ -49,6 +50,7 @@ library.
:maxdepth: 1
cmath.rst
_collections.rst
gc.rst
math.rst
select.rst
...
...
@@ -85,6 +87,7 @@ library.
.. toctree::
:maxdepth: 1
_collections.rst
gc.rst
math.rst
sys.rst
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment