-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c0d59b
commit 069ef32
Showing
52 changed files
with
1,371 additions
and
567 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
=========== | ||
Definitions | ||
=========== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,18 @@ | ||
Fundamental Data Types | ||
================== | ||
=========== | ||
Boilerplate | ||
=========== | ||
|
||
Numbers | ||
--------------------------- | ||
* | ||
if __name__ == '__main__': main() | ||
---------------------------------- | ||
|
||
Strings | ||
#! /usr/bin/env python | ||
---------------------- | ||
* | ||
|
||
Lists | ||
----------------------- | ||
* | ||
#! /usr/local/bin/python | ||
------------------------ | ||
|
||
Dictionaries | ||
------------------------- | ||
* | ||
|
||
Tuples | ||
------ | ||
* | ||
|
||
Sets | ||
----------- | ||
* | ||
#! /usr/bin/python | ||
------------------ | ||
|
||
# -*- coding: utf-8 -*- | ||
----------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
===================== | ||
[ , ..., ] (ellipsis) | ||
===================== | ||
|
||
Description | ||
=========== | ||
Gives access to a specified range of array's elements. | ||
|
||
Syntax | ||
====== | ||
**array** *[ , ..., ]* | ||
|
||
Return Value | ||
============ | ||
The same as selected. | ||
|
||
Time Complexity | ||
=============== | ||
#TODO | ||
|
||
Remarks | ||
======= | ||
|
||
Ellipsis is used for slicing multidimensional numpy arrays. | ||
|
||
The ellipsis syntax may be used to indicate selecting in full any remaining unspecified dimensions. | ||
|
||
Example | ||
======= | ||
>>> n = numpy.arange(16).reshape(2, 2, 2, 2) | ||
>>> n | ||
array([[[[ 0, 1], | ||
[ 2, 3]], | ||
|
||
[[ 4, 5], | ||
[ 6, 7]]], | ||
|
||
|
||
[[[ 8, 9], | ||
[10, 11]], | ||
|
||
[[12, 13], | ||
[14, 15]]]]) | ||
>>> n[1,...,1] # equivalent to n[1,:,:,1] | ||
array([[ 9, 11], | ||
[13, 15]]) | ||
>>> # also Ellipsis object can be used interchangeably | ||
>>> n[1, Ellipsis, 1] | ||
array([[ 9, 11], | ||
[13, 15]]) | ||
|
||
See Also | ||
======== | ||
#TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
======================== | ||
[] (index operator) | ||
======================== | ||
|
||
Description | ||
=========== | ||
Gives access to a sequence's element. | ||
|
||
Syntax | ||
====== | ||
**sequence** *[index]* | ||
|
||
*index* | ||
Index of the item you want to access. Must be an integer. | ||
|
||
Return Value | ||
============ | ||
The same as selected. | ||
|
||
Time Complexity | ||
=============== | ||
#TODO | ||
|
||
Discussion | ||
========== | ||
The built-in fundamental sequence types are: | ||
|
||
* strings - str and unicode | ||
* arrays - list and tuple | ||
|
||
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. | ||
|
||
Consider the following ASCII graph showing the contents of the "ABCD" string: | ||
|
||
>>> +---+---+---+---+ | ||
>>> |-4 |-3 |-2 |-1 | <= negative indexes | ||
>>> +---+---+---+---+ | ||
>>> | A | B | C | D | <= sequence elements | ||
>>> +---+---+---+---+ | ||
>>> | 0 | 1 | 2 | 3 | <= positive indexes | ||
>>> +---+---+---+---+ | ||
|
||
Remarks | ||
======= | ||
The number of items in a sequence cam be retrieved by using `len()`_ function: | ||
|
||
>>> len("ABCD") | ||
4 | ||
>>> len([0, 1, 2]) | ||
3 | ||
|
||
Trying to access an element out of range throws an IndexError. | ||
|
||
Example 1 | ||
========= | ||
>>> # this example show how to retrieve elements of a sequence | ||
>>> "ABCD"[0] | ||
'A' | ||
>>> [0, 1, 2][1] | ||
1 | ||
>>> ("ABC", "DEF", "GHI")[1] | ||
'DEF' | ||
|
||
Example 2 | ||
========= | ||
>>> # index lookups can be chained to access nested containers | ||
>>> ([0, 1], [2, 3])[1][1] | ||
3 | ||
|
||
Example 3 | ||
========= | ||
>>> # using negative indexes to get the last element | ||
>>> (0, 1, 2)[-1] | ||
2 | ||
>>> "ABCD"[-1] | ||
'D' | ||
|
||
Example 4 | ||
========= | ||
>>> # since lists are mutable indexes can be used for item assignment or deletion | ||
>>> l = [0, 1, 2, 3] | ||
>>> l[0] = "ABCD" | ||
>>> l | ||
['ABCD', 1, 2, 3] | ||
|
||
Example 5 | ||
========= | ||
>>> l = [0, 1, 2, 3] | ||
>>> del l[2] | ||
>>> l | ||
[0, 1, 3] | ||
|
||
See Also | ||
======== | ||
#TODO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
=============== | ||
[] (key lookup) | ||
=============== | ||
|
||
Description | ||
=========== | ||
Returns the value associated with the given key. | ||
|
||
Syntax | ||
====== | ||
**dict** *[key]* | ||
|
||
*key* | ||
Required. Key which value is to be retrieved. | ||
|
||
Return Value | ||
============ | ||
The same as associated with key. | ||
|
||
Time Complexity | ||
=============== | ||
#TODO | ||
|
||
Remarks | ||
======= | ||
If *key* is not found throws *KeyError*. | ||
|
||
Example | ||
======= | ||
>>> {'a': 1, 'b': 2}['a'] | ||
1 | ||
|
||
See Also | ||
======== | ||
#TODO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
============== | ||
[] (slicing) | ||
============== | ||
|
||
Description | ||
=========== | ||
Gives access to a specified range of sequence's elements. | ||
|
||
Syntax | ||
====== | ||
**sequence** *[start:stop[:step]]* | ||
|
||
*start* | ||
Optional. Starting index of the slice. Defaults to 0. | ||
*stop* | ||
Optional. The last index of the slice or the number of items to get. Defaults to *len(sequence)*. | ||
*step* | ||
Optional. Extended slice syntax. Step value of the slice. Defaults to 1. | ||
|
||
Return Value | ||
============ | ||
The same as selected. | ||
|
||
Time Complexity | ||
=============== | ||
#TODO | ||
|
||
Remarks | ||
======= | ||
Consider the following ASCII graph showing the contents of the "ABCD" string: | ||
|
||
>>> +---+---+---+---+ | ||
>>> |-4 |-3 |-2 |-1 | <= negative indexes | ||
>>> +---+---+---+---+ | ||
>>> | A | B | C | D | <= sequence elements | ||
>>> +---+---+---+---+ | ||
>>> | 0 | 1 | 2 | 3 | <= positive indexes | ||
>>> +---+---+---+---+ | ||
>>> |<- 0:3:1 ->| <= extent of the slice: "ABCD"[0:3:1] | ||
|
||
|
||
Consider the following example: | ||
|
||
Example 1 | ||
========= | ||
>>> "ABCD"[0:2] | ||
'AB' | ||
|
||
It can be read as: get every single one item between indexes 0 and 2 (exclusive). | ||
|
||
The next example shows usage of the *step* argument: | ||
|
||
Example 2 | ||
========= | ||
>>> "ABCD"[0:4:2] | ||
'AC' | ||
|
||
That can be interpreted as: get every second element between indexes 0 and 4. | ||
|
||
Usage of start, stop and step operators is optional: | ||
|
||
Example 3 | ||
========= | ||
>>> "ABCD"[1:] | ||
'BCD' | ||
>>> "ABCD"[:3] | ||
'ABC' | ||
>>> "ABCD"[1:3] | ||
'BC' | ||
>>> "ABCD"[1:3:] | ||
'BC' | ||
>>> "ABCD"[::2] | ||
'AC' | ||
>>> "ABCD"[::] | ||
'ABCD' | ||
>>> "ABCD"[:] | ||
'ABCD' | ||
|
||
Negative step argument can be used to reverse the sequence: | ||
|
||
Example 4 | ||
========= | ||
>>> "ABCD"[::-1] | ||
'DCBA' | ||
>>> [0, 1, 2, 3][::-1] | ||
[3, 2, 1, 0] | ||
|
||
Example 5 | ||
========= | ||
>>> # slices can be used to replace multiple items | ||
>>> l = [0, 1, 2, 3] | ||
>>> l[:2] = ("AB", "CD") | ||
>>> l | ||
['AB', 'CD', 2, 3] | ||
|
||
Example 6 | ||
========= | ||
>>> l = [0, 1, 2, 3] | ||
>>> l[1:2] = (7, 8, 9, 10) | ||
>>> l | ||
[0, 7, 8, 9, 10, 2, 3] | ||
|
||
Example 7 | ||
========= | ||
>>> # when using extended slice syntax both chunks must match | ||
>>> l = [0, 1, 2, 3] | ||
>>> l[::2] = "ABCD" | ||
Traceback (most recent call last): | ||
File "<interactive input>", line 1, in <module> | ||
ValueError: attempt to assign sequence of size 4 to extended slice of size 2 | ||
|
||
Example 8 | ||
========= | ||
>>> # deleting items | ||
>>> l = [0, 1, 2, 3] | ||
>>> del l[::2] | ||
>>> l | ||
[1, 3] | ||
|
||
See Also | ||
======== | ||
#TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.