Skip to content

Commit 1a98d1b

Browse files
committed
A
1 parent 069ef32 commit 1a98d1b

15 files changed

Lines changed: 402 additions & 114 deletions

File tree

source/definitions.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
===========
12
Definitions
23
===========

source/docs/boilerplate/index.rst

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
Fundamental Data Types
2-
==================
1+
===========
2+
Boilerplate
3+
===========
34

4-
Numbers
5-
---------------------------
6-
*
5+
if __name__ == '__main__': main()
6+
----------------------------------
77

8-
Strings
8+
#! /usr/bin/env python
99
----------------------
10-
*
1110

12-
Lists
13-
-----------------------
14-
*
11+
#! /usr/local/bin/python
12+
------------------------
1513

16-
Dictionaries
17-
-------------------------
18-
*
19-
20-
Tuples
21-
------
22-
*
23-
24-
Sets
25-
-----------
26-
*
14+
#! /usr/bin/python
15+
------------------
2716

17+
# -*- coding: utf-8 -*-
18+
-----------------------

source/docs/brackets/ellipsis.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
=====================
2+
[ , ..., ] (ellipsis)
3+
=====================
4+
5+
Description
6+
===========
7+
Gives access to a specified range of array's elements.
8+
9+
Syntax
10+
======
11+
**array** *[ , ..., ]*
12+
13+
Return Value
14+
============
15+
The same as selected.
16+
17+
Time Complexity
18+
===============
19+
#TODO
20+
21+
Remarks
22+
=======
23+
24+
Ellipsis is used for slicing multidimensional numpy arrays.
25+
26+
The ellipsis syntax may be used to indicate selecting in full any remaining unspecified dimensions.
27+
28+
Example
29+
=======
30+
>>> n = numpy.arange(16).reshape(2, 2, 2, 2)
31+
>>> n
32+
array([[[[ 0, 1],
33+
[ 2, 3]],
34+
35+
[[ 4, 5],
36+
[ 6, 7]]],
37+
38+
39+
[[[ 8, 9],
40+
[10, 11]],
41+
42+
[[12, 13],
43+
[14, 15]]]])
44+
>>> n[1,...,1] # equivalent to n[1,:,:,1]
45+
array([[ 9, 11],
46+
[13, 15]])
47+
>>> # also Ellipsis object can be used interchangeably
48+
>>> n[1, Ellipsis, 1]
49+
array([[ 9, 11],
50+
[13, 15]])
51+
52+
See Also
53+
========
54+
#TODO

source/docs/brackets/indexing.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
========================
2+
[] (index operator)
3+
========================
4+
5+
Description
6+
===========
7+
Gives access to a sequence's element.
8+
9+
Syntax
10+
======
11+
**sequence** *[index]*
12+
13+
*index*
14+
Index of the item you want to access. Must be an integer.
15+
16+
Return Value
17+
============
18+
The same as selected.
19+
20+
Time Complexity
21+
===============
22+
#TODO
23+
24+
Discussion
25+
==========
26+
The built-in fundamental sequence types are:
27+
28+
* strings - str and unicode
29+
* arrays - list and tuple
30+
31+
Since all sequences are ordered and indexed arrays of objects, each object stored in a sequence has it's associated index number - positive one, zero indexed and starting from left, and the negative one starting at -1 from the right.
32+
33+
Consider the following ASCII graph showing the contents of the "ABCD" string:
34+
35+
>>> +---+---+---+---+
36+
>>> |-4 |-3 |-2 |-1 | <= negative indexes
37+
>>> +---+---+---+---+
38+
>>> | A | B | C | D | <= sequence elements
39+
>>> +---+---+---+---+
40+
>>> | 0 | 1 | 2 | 3 | <= positive indexes
41+
>>> +---+---+---+---+
42+
43+
Remarks
44+
=======
45+
The number of items in a sequence cam be retrieved by using `len()`_ function:
46+
47+
>>> len("ABCD")
48+
4
49+
>>> len([0, 1, 2])
50+
3
51+
52+
Trying to access an element out of range throws an IndexError.
53+
54+
Example 1
55+
=========
56+
>>> # this example show how to retrieve elements of a sequence
57+
>>> "ABCD"[0]
58+
'A'
59+
>>> [0, 1, 2][1]
60+
1
61+
>>> ("ABC", "DEF", "GHI")[1]
62+
'DEF'
63+
64+
Example 2
65+
=========
66+
>>> # index lookups can be chained to access nested containers
67+
>>> ([0, 1], [2, 3])[1][1]
68+
3
69+
70+
Example 3
71+
=========
72+
>>> # using negative indexes to get the last element
73+
>>> (0, 1, 2)[-1]
74+
2
75+
>>> "ABCD"[-1]
76+
'D'
77+
78+
Example 4
79+
=========
80+
>>> # since lists are mutable indexes can be used for item assignment or deletion
81+
>>> l = [0, 1, 2, 3]
82+
>>> l[0] = "ABCD"
83+
>>> l
84+
['ABCD', 1, 2, 3]
85+
86+
Example 5
87+
=========
88+
>>> l = [0, 1, 2, 3]
89+
>>> del l[2]
90+
>>> l
91+
[0, 1, 3]
92+
93+
See Also
94+
========
95+
#TODO
96+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
===============
2+
[] (key lookup)
3+
===============
4+
5+
Description
6+
===========
7+
Returns the value associated with the given key.
8+
9+
Syntax
10+
======
11+
**dict** *[key]*
12+
13+
*key*
14+
Required. Key which value is to be retrieved.
15+
16+
Return Value
17+
============
18+
The same as associated with key.
19+
20+
Time Complexity
21+
===============
22+
#TODO
23+
24+
Remarks
25+
=======
26+
If *key* is not found throws *KeyError*.
27+
28+
Example
29+
=======
30+
>>> {'a': 1, 'b': 2}['a']
31+
1
32+
33+
See Also
34+
========
35+
#TODO
36+

source/docs/brackets/slicing.rst

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
==============
2+
[] (slicing)
3+
==============
4+
5+
Description
6+
===========
7+
Gives access to a specified range of sequence's elements.
8+
9+
Syntax
10+
======
11+
**sequence** *[start:stop[:step]]*
12+
13+
*start*
14+
Optional. Starting index of the slice. Defaults to 0.
15+
*stop*
16+
Optional. The last index of the slice or the number of items to get. Defaults to *len(sequence)*.
17+
*step*
18+
Optional. Extended slice syntax. Step value of the slice. Defaults to 1.
19+
20+
Return Value
21+
============
22+
The same as selected.
23+
24+
Time Complexity
25+
===============
26+
#TODO
27+
28+
Remarks
29+
=======
30+
Consider the following ASCII graph showing the contents of the "ABCD" string:
31+
32+
>>> +---+---+---+---+
33+
>>> |-4 |-3 |-2 |-1 | <= negative indexes
34+
>>> +---+---+---+---+
35+
>>> | A | B | C | D | <= sequence elements
36+
>>> +---+---+---+---+
37+
>>> | 0 | 1 | 2 | 3 | <= positive indexes
38+
>>> +---+---+---+---+
39+
>>> |<- 0:3:1 ->| <= extent of the slice: "ABCD"[0:3:1]
40+
41+
42+
Consider the following example:
43+
44+
Example 1
45+
=========
46+
>>> "ABCD"[0:2]
47+
'AB'
48+
49+
It can be read as: get every single one item between indexes 0 and 2 (exclusive).
50+
51+
The next example shows usage of the *step* argument:
52+
53+
Example 2
54+
=========
55+
>>> "ABCD"[0:4:2]
56+
'AC'
57+
58+
That can be interpreted as: get every second element between indexes 0 and 4.
59+
60+
Usage of start, stop and step operators is optional:
61+
62+
Example 3
63+
=========
64+
>>> "ABCD"[1:]
65+
'BCD'
66+
>>> "ABCD"[:3]
67+
'ABC'
68+
>>> "ABCD"[1:3]
69+
'BC'
70+
>>> "ABCD"[1:3:]
71+
'BC'
72+
>>> "ABCD"[::2]
73+
'AC'
74+
>>> "ABCD"[::]
75+
'ABCD'
76+
>>> "ABCD"[:]
77+
'ABCD'
78+
79+
Negative step argument can be used to reverse the sequence:
80+
81+
Example 4
82+
=========
83+
>>> "ABCD"[::-1]
84+
'DCBA'
85+
>>> [0, 1, 2, 3][::-1]
86+
[3, 2, 1, 0]
87+
88+
Example 5
89+
=========
90+
>>> # slices can be used to replace multiple items
91+
>>> l = [0, 1, 2, 3]
92+
>>> l[:2] = ("AB", "CD")
93+
>>> l
94+
['AB', 'CD', 2, 3]
95+
96+
Example 6
97+
=========
98+
>>> l = [0, 1, 2, 3]
99+
>>> l[1:2] = (7, 8, 9, 10)
100+
>>> l
101+
[0, 7, 8, 9, 10, 2, 3]
102+
103+
Example 7
104+
=========
105+
>>> # when using extended slice syntax both chunks must match
106+
>>> l = [0, 1, 2, 3]
107+
>>> l[::2] = "ABCD"
108+
Traceback (most recent call last):
109+
File "<interactive input>", line 1, in <module>
110+
ValueError: attempt to assign sequence of size 4 to extended slice of size 2
111+
112+
Example 8
113+
=========
114+
>>> # deleting items
115+
>>> l = [0, 1, 2, 3]
116+
>>> del l[::2]
117+
>>> l
118+
[1, 3]
119+
120+
See Also
121+
========
122+
#TODO

source/docs/dict/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Constructors
1313
`{} dict comprehension`_
1414
Returns a dictionary based on existing iterables.
1515
`literal syntax`_
16+
17+
Misc
18+
----
19+
`[] (key lookup)`_
20+
Returns the value associated with the given key.
1621

1722
Methods
1823
-------
@@ -81,6 +86,7 @@ __________________________
8186
Returns all the elements that appear in the dictview and the specified iterable.
8287

8388
.. _dict(): ../functions/dict.html
89+
.. _[] (key lookup): ../brackets/key_lookup.html
8490
.. _{} dict comprehension: ../comprehensions/dict_comprehension.html
8591
.. _literal syntax: literals.html
8692
.. _update: update.html

0 commit comments

Comments
 (0)