# Create a [list] 
days = ['Monday', # multiple lines 
        'Tuesday', # acceptable 
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday', 
       ] # trailing comma is fine!

days

# Simple for-loop
for day in days:
    print day

# Double for-loop
for day in days:
    for letter in day:
        print letter,

# Double for-loop
for day in days:
    for letter in day:
        print letter,
    print 

for day in days:
    for letter in day:
        print letter.lower(), 

"""
Explanation: Github
https://github.com/jbwhit/OSCON-2015/commit/6750b962606db27f69162b802b5de4f84ac916d5
A few Python Basics
Style Guide for Python Code: http://www.python.org/dev/peps/pep-0008/
End of explanation
"""


length_of_days = [len(day) for day in days]
length_of_days

letters = [letter for day in days
                       for letter in day]

letters = [letter for day in days for letter in day]
print letters 

[num for num in xrange(10) if num % 2]

[num for num in xrange(10) if num % 2 else "doesn't work"]

[num if num % 2 else "works" for num in xrange(10)]

sorted_letters = sorted([x.lower() for x in letters])
print sorted_letters

unique_sorted_letters = sorted(set(sorted_letters))

print "There are", len(unique_sorted_letters), "unique letters in the days of the week."
print "They are:", ''.join(unique_sorted_letters) 

print "They are:", '; '.join(unique_sorted_letters) 

def first_three(input_string):
    """Takes an input string and returns the first 3 characters."""
    return input_string[:3] 

[first_three(day) for day in days]

def last_N(input_string, number=2):
    """Takes an input string and returns the last N characters."""
    return input_string[-number:] 

[last_N(day, 153) for day in days if len(day) > 6]

from math import pi

print [str(round(pi, i)) for i in xrange(2, 9)] 

list_of_lists = [[i, round(pi, i)] for i in xrange(2, 9)]
print list_of_lists

for sublist in list_of_lists:
    print sublist

# Let this be a warning to you!

# If you see python code like the following in your work:

for x in range(len(list_of_lists)):
    print "Decimals:", list_of_lists[x][0], 
    print "expression:", list_of_lists[x][1]
    

# Change it to look more like this: 

for decimal, rounded_pi in list_of_lists:
    print "Decimals:", decimal, "expression:", rounded_pi
    
print list_of_lists

# enumerate if you really need the index

for index, day in enumerate(days):
    print index, day


"""
Explanation: List Comprehensions
End of explanation
"""


from IPython.display import IFrame, HTML
HTML('<iframe src=https://en.wikipedia.org/wiki/Hash_table width=100% height=550></iframe>')

fellows = ["Jonathan", "Zach", "Matt", "Wafa"]
sessions = ["2014-C", "2014-C", "2014-A", "2014-B"]

dict(zip(fellows, sessions))

insight = {fellow.lower(): session for fellow, session in zip(fellows, sessions)}

insight

# Standard Libraries
# collections; Counter, 
#

insight['matt']

rounded_pi = {i:round(pi, i) for i in xrange(2, 9)}

rounded_pi[5]

"""
Explanation: Dictionaries
Python dictionaries are awesome. They are hash tables and have a lot of neat CS properties. Learn and use them well.
End of explanation
"""


# This broke!
# There are multiple extensions that allow for R to be executed, this is merely one of them
# I don't use it so I don't know if there's something better. 
# You have to install R as well. 
%load_ext rpy2.ipython

X = np.array([0,1,2,3,4])
Y = np.array([3,5,4,6,7])

%%R -i X,Y -o XYcoef
XYlm = lm(Y~X)
XYcoef = coef(XYlm)
print(summary(XYlm))
par(mfrow=c(2,2))
plot(XYlm)

FileLink("Overview.ipynb")

"""
Explanation: Participate in StackOverflow
An example: http://stackoverflow.com/questions/6605006/convert-pdf-to-image-with-high-resolution
Julia Notebook
http://nbviewer.ipython.org/github/shashi/ijulia-notebooks/blob/master/funcgeo/Functional%20Geometry.ipynb
Extensions
https://github.com/ipython/ipython/wiki/Extensions-Index
R or Julia or Haskell or... SQL (get to that later)
You can use R as well -- I don't use it at all, so I took this small example below from http://nbviewer.ipython.org/github/ipython/ipython/blob/3607712653c66d63e0d7f13f073bde8c0f209ba8/docs/examples/notebooks/rmagic_extension.ipynb.
End of explanation
"""


