Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzywoski committed Feb 10, 2015
1 parent 2c0d59b commit 069ef32
Show file tree
Hide file tree
Showing 52 changed files with 1,371 additions and 567 deletions.
Binary file modified build/doctrees/definitions.doctree
Binary file not shown.
Binary file modified build/doctrees/docs/boilerplate/index.doctree
Binary file not shown.
Binary file added build/doctrees/docs/brackets/ellipsis.doctree
Binary file not shown.
Binary file added build/doctrees/docs/brackets/indexing.doctree
Binary file not shown.
Binary file added build/doctrees/docs/brackets/key_lookup.doctree
Binary file not shown.
Binary file added build/doctrees/docs/brackets/slicing.doctree
Binary file not shown.
Binary file modified build/doctrees/docs/dict/index.doctree
Binary file not shown.
Binary file modified build/doctrees/docs/list/index.doctree
Binary file not shown.
Binary file modified build/doctrees/docs/operators/index.doctree
Binary file not shown.
Binary file modified build/doctrees/docs/str/index.doctree
Binary file not shown.
Binary file modified build/doctrees/docs/tuple/index.doctree
Binary file not shown.
Binary file modified build/doctrees/dunders.doctree
Binary file not shown.
Binary file modified build/doctrees/environment.pickle
Binary file not shown.
Binary file modified build/doctrees/exceptions.doctree
Binary file not shown.
Binary file modified build/doctrees/index.doctree
Binary file not shown.
Binary file modified build/doctrees/operators.doctree
Binary file not shown.
Binary file modified build/doctrees/statements.doctree
Binary file not shown.
1 change: 1 addition & 0 deletions build/html/_sources/definitions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
===========
Definitions
===========
33 changes: 12 additions & 21 deletions build/html/_sources/docs/boilerplate/index.txt
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 -*-
-----------------------
54 changes: 54 additions & 0 deletions build/html/_sources/docs/brackets/ellipsis.txt
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
96 changes: 96 additions & 0 deletions build/html/_sources/docs/brackets/indexing.txt
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

36 changes: 36 additions & 0 deletions build/html/_sources/docs/brackets/key_lookup.txt
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

122 changes: 122 additions & 0 deletions build/html/_sources/docs/brackets/slicing.txt
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
6 changes: 6 additions & 0 deletions build/html/_sources/docs/dict/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Constructors
`{} dict comprehension`_
Returns a dictionary based on existing iterables.
`literal syntax`_

Misc
----
`[] (key lookup)`_
Returns the value associated with the given key.

Methods
-------
Expand Down Expand Up @@ -81,6 +86,7 @@ __________________________
Returns all the elements that appear in the dictview and the specified iterable.

.. _dict(): ../functions/dict.html
.. _[] (key lookup): ../brackets/key_lookup.html
.. _{} dict comprehension: ../comprehensions/dict_comprehension.html
.. _literal syntax: literals.html
.. _update: update.html
Expand Down

0 comments on commit 069ef32

Please sign in to comment.