Skip to content

Commit

Permalink
Conversion of all rst to corresponding markdown files
Browse files Browse the repository at this point in the history
We use git-flavoured markdown
  • Loading branch information
pipitone committed Feb 3, 2013
1 parent 0c69b6c commit 4ba1cf2
Show file tree
Hide file tree
Showing 35 changed files with 3,847 additions and 4,125 deletions.
31 changes: 20 additions & 11 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
This collection of material is licensed under a Creative Commons - Attribution license.
This collection of material is licensed under a Creative Commons - Attribution
license.

You are free:

- to **Share**to copy, distribute and transmit the work
- to **Remix**to adapt the work
- to **Share** - to copy, distribute and transmit the work
- to **Remix** - to adapt the work

Under the following conditions:

- **Attribution**—You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
- **Attribution** - You must attribute the work in the manner specified by the
author or licensor (but not in any way that suggests that they endorse you or
your use of the work).

With the understanding that:

- **Waiver**—Any of the above conditions can be waived if you get permission from the copyright holder.
- **Other Rights**—In no way are any of the following rights affected by the license:
-- Your fair dealing or fair use rights;
-- The author’s moral rights;
-- Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
- **Notice**—For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this [web page](http://creativecommons.org/licenses/by/3.0/).
- **Waiver** - Any of the above conditions can be waived if you get permission
from the copyright holder.
- **Other Rights** - In no way are any of the following rights affected by the
license:
- Your fair dealing or fair use rights;
- The author’s moral rights;
- Rights other persons may have either in the work itself or in how the work
is used, such as publicity or privacy rights.
- **Notice** - For any reuse or distribution, you must make clear to others the
license terms of this work. The best way to do this is with a link to this
[web page](http://creativecommons.org/licenses/by/3.0/).

For the full legal text of this license, please see http://creativecommons.org/licenses/by/3.0/legalcode.
For the full legal text of this license, please see
http://creativecommons.org/licenses/by/3.0/legalcode.
96 changes: 70 additions & 26 deletions python/data_structures/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

* * * * *

**Based on lecture materials by Milad Fatenejad, Joshua R. Smith, and Will Trimble**
**Based on lecture materials by Milad Fatenejad, Joshua R. Smith, and Will
Trimble**

Python would be a farily useless language if it weren't for the compound data types. The main two are lists and dictionaries, but I'll mention sets and tuples as well. I'll also go over reading text data from files.
Python would be a farily useless language if it weren't for the compound
data types. The main two are lists and dictionaries, but I'll mention sets
and tuples as well. I'll also go over reading text data from files.

## Lists

A list is an ordered, indexable collection of data. Lets say you have collected some current and voltage data that looks like this:
A list is an ordered, indexable collection of data. Lets say you have
collected some current and voltage data that looks like this:

```
voltage:
Expand Down Expand Up @@ -41,7 +45,8 @@ In [3]: type(voltageList)
Out[3]: <type 'list'>
```

Python lists have the charming (annoying?) feature that they are indexed from zero. Therefore, to find the value of the first item in voltageList:
Python lists have the charming (annoying?) feature that they are indexed
from zero. Therefore, to find the value of the first item in voltageList:

```python
In [4]: voltageList[0]
Expand All @@ -55,7 +60,8 @@ In [5]: voltageList[2]
Out[5]: 0.0
```

Lists can be indexed from the back using a negative index. The last item of currentList
Lists can be indexed from the back using a negative index. The last item of
currentList

```python
In [6]: currentList[-1]
Expand All @@ -69,7 +75,8 @@ In [7]: currentList[-2]
Out[7]: 0.5
```

You can "slice" items from within a list. Lets say we wanted the second through fourth items from voltageList
You can "slice" items from within a list. Lets say we wanted the second
through fourth items from voltageList

```python
In [8]: voltageList[1:4]
Expand All @@ -93,7 +100,8 @@ Just like strings have methods, lists do too.
In [10] dir(list)
```

One useful method is append. Lets say we want to stick the following data on the end of both our lists.
One useful method is append. Lets say we want to stick the following data
on the end of both our lists.

```
voltage:
Expand All @@ -116,7 +124,8 @@ In [13]: voltageList
Out[13]: [-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0]
```

You can see how that approach might be tedious in certain cases. If you want to concatenate a list onto the end of another one, use extend.
You can see how that approach might be tedious in certain cases. If you
want to concatenate a list onto the end of another one, use extend.

```python
In [14]: currentList.extend([1.5, 2.0])
Expand Down Expand Up @@ -147,11 +156,16 @@ In [17]: dataList = ["experiment: current vs. voltage", \

```

We've got strings, ints, floats, and even other lists in there. The slashes are there so we can continue on the next line. They aren't necessary but they can sometimes make things look better.
We've got strings, ints, floats, and even other lists in there. The slashes
are there so we can continue on the next line. They aren't necessary but
they can sometimes make things look better.

## Assigning Variables to Other Variables

Something that might cause you headaches in the future is how python deals with assignment of one variable to another. When you set a variable equal to another, both variables point to the same thing. Changing the first one ends up changing the second. Be careful about this fact.
Something that might cause you headaches in the future is how python deals
with assignment of one variable to another. When you set a variable equal
to another, both variables point to the same thing. Changing the first one
ends up changing the second. Be careful about this fact.

```python
In [19]: a = [1,2]
Expand All @@ -164,11 +178,13 @@ In [22]: b
Out[22]: [1, 2, 10]
```

There's a ton more to know about lists, but lets press on. Check out Dive Into Python or the help documentation for more info.
There's a ton more to know about lists, but lets press on. Check out Dive
Into Python or the help documentation for more info.

## Reading From Files

At this point it is useful to take a detour regarding files. Lets say you have a file with some current and voltage data and some metadata.
At this point it is useful to take a detour regarding files. Lets say you
have a file with some current and voltage data and some metadata.

```
data.dat:
Expand Down Expand Up @@ -199,11 +215,15 @@ Out[4]:
'\n']
```

Right now the data in ivdata isn't in a particularly useful format, but you can imagine that with some additional programming we could straighten it out. We will eventually do that.
Right now the data in ivdata isn't in a particularly useful format, but you
can imagine that with some additional programming we could straighten it
out. We will eventually do that.

## Tuples

Tuples are another of python's basic compound data types that are almost like lists. The difference is that a tuple is immutable; once you set the data in it, the tuple cannot be changed. You define a tuple as follows.
Tuples are another of python's basic compound data types that are almost
like lists. The difference is that a tuple is immutable; once you set the
data in it, the tuple cannot be changed. You define a tuple as follows.

```python
In [1]: tup = ("red", "white", "blue")
Expand All @@ -212,19 +232,27 @@ In [2]: type(tup)
Out[2]: <type 'tuple'>
```

You can slice and index the tuple exactly like you would a list. Tuples are used in the inner workings of python, and a tuple can be used as a key in a dictionary, whereas a list cannot as we will see in a moment.
You can slice and index the tuple exactly like you would a list. Tuples are
used in the inner workings of python, and a tuple can be used as a key in a
dictionary, whereas a list cannot as we will see in a moment.

## Sets

Most introductary python courses do not go over sets this early (or at all), but I've found this data type to be useful. The python set type is similar to the idea of a mathematical set: it is an unordered collection of unique things. Consider:
Most introductary python courses do not go over sets this early (or at
all), but I've found this data type to be useful. The python set type is
similar to the idea of a mathematical set: it is an unordered collection of
unique things. Consider:

```python
In [3] fruit = set(["apple", "banana", "pear", "banana"]) #You have to use a list to create a set.
```

Since sets contain only unique items, there's only one banana in the set fruit.
Since sets contain only unique items, there's only one banana in the set
fruit.

You can do things like intersections, unions, etc. on sets just like in math. Here's an example of an intersection of two sets (the common items in both sets).
You can do things like intersections, unions, etc. on sets just like in
math. Here's an example of an intersection of two sets (the common items in
both sets).

```python
In [4]: firstBowl = set(["apple", "banana", "pear", "peach"])
Expand All @@ -235,11 +263,18 @@ In [6]: set.intersection(firstBowl, secondBowl)
Out[6]: set(['apple', 'peach'])
```

You can check out more info using the help docs. We won't be returning to sets, but its good for you to know they exist.
You can check out more info using the help docs. We won't be returning to
sets, but its good for you to know they exist.

## Dictionaries

Recall our file data.dat which contained our current-voltage data and also some metadata. We were able to import the data as a list, but clearly the list type is not the optial choice for a data model. The dictionary is a much better choice. A python dictionary is a collection of key, value pairs. The key is a way to name the data, and the value is the data itself. Here's a way to create a dictionary that contains all the data in our data.dat file in a more sensible way than a list.
Recall our file data.dat which contained our current-voltage data and also
some metadata. We were able to import the data as a list, but clearly the
list type is not the optial choice for a data model. The dictionary is a
much better choice. A python dictionary is a collection of key, value
pairs. The key is a way to name the data, and the value is the data itself.
Here's a way to create a dictionary that contains all the data in our
data.dat file in a more sensible way than a list.

```python
In [7] dataDict = {"experiment": "current vs. voltage", \
Expand All @@ -249,7 +284,9 @@ In [7] dataDict = {"experiment": "current vs. voltage", \
"voltage": [-2.0, -1.0, 0.0, 1.0, 2.0]}
```

This model is clearly better because you no longer have to remember that the run number is in the second position of the list, you just refer directly to "run":
This model is clearly better because you no longer have to remember that
the run number is in the second position of the list, you just refer
directly to "run":

```python
In [9]: dataDict["run"]
Expand All @@ -270,7 +307,8 @@ In [11]: dataDict["current"][-1]
Out[11]: 1.0
```

Once a dictionary has been created, you can change the values of the data if you like.
Once a dictionary has been created, you can change the values of the data
if you like.

```python
In [12]: dataDict["temperature"] = 3275.39
Expand All @@ -282,7 +320,8 @@ You can also add new keys to the dictionary.
In [13]: dataDict["user"] = "Johann G. von Ulm"
```

Dictionaries, like strings, lists, and all the rest, have built-in methods. Lets say you wanted all the keys from a particular dictionary.
Dictionaries, like strings, lists, and all the rest, have built-in methods.
Lets say you wanted all the keys from a particular dictionary.

```python
In [14]: dataDict.keys()
Expand All @@ -304,8 +343,13 @@ Out[15]:

The help documentation has more information about what dictionaries can do.

Its worth mentioning that the value part of a dictionary can be any kind of data, even another dictionary, or some complex nested structure. The same is true about a list: they can contain complex data types.
Its worth mentioning that the value part of a dictionary can be any kind of
data, even another dictionary, or some complex nested structure. The same
is true about a list: they can contain complex data types.

Since tuples are immutable, they can be used as keys for dictionaries. Lists are mutable, and therefore cannot.
Since tuples are immutable, they can be used as keys for dictionaries.
Lists are mutable, and therefore cannot.

When you architect software in python, most data will end up looking either like a list or a dictionary. These two data types are very important in python and you'll end up using them all the time.
When you architect software in python, most data will end up looking either
like a list or a dictionary. These two data types are very important in
python and you'll end up using them all the time.
29 changes: 14 additions & 15 deletions python/documentation/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ Readme files are so common that GitHub will render and display the
readme file for all directories whenever you are browsing a source tree.
Even Linux itself has a readme:

Linux kernel release 3.x <http://kernel.org/>

> Linux kernel release 3.x <http://kernel.org/>
>
> These are the release notes for Linux version 3. Read them carefully,
> as they tell you what this is all about, explain how to install the
> kernel, and what to do if something goes wrong.
>
> WHAT IS LINUX?
>
> > Linux is a clone of the operating system Unix, written from scratch
> > by Linus Torvalds with assistance from a loosely-knit team of
> > hackers across the Net. It aims towards POSIX and Single UNIX
> > Specification compliance.
> >
> > It has all the features you would expect in a modern fully-fledged
> > Unix, including true multitasking, virtual memory, shared libraries,
> > demand loading, shared copy-on-write executables, proper memory
> > management, and multistack networking including IPv4 and IPv6.
> >
> > It is distributed under the GNU General Public License - see the
> > accompanying COPYING file for more details.
> Linux is a clone of the operating system Unix, written from scratch
> by Linus Torvalds with assistance from a loosely-knit team of
> hackers across the Net. It aims towards POSIX and Single UNIX
> Specification compliance.
>
> It has all the features you would expect in a modern fully-fledged
> Unix, including true multitasking, virtual memory, shared libraries,
> demand loading, shared copy-on-write executables, proper memory
> management, and multistack networking including IPv4 and IPv6.
>
> It is distributed under the GNU General Public License - see the
> accompanying COPYING file for more details.
>
> ...
Expand Down Expand Up @@ -287,4 +287,3 @@ LaTeX.

Add docstrings to the functions in the `close_line.py` module. Then,
using sphinx, generate a website which auto-documents this module.

Loading

0 comments on commit 4ba1cf2

Please sign in to comment.